├── ChangeLog ├── MIMOSA_VERSION ├── .gitignore ├── AUTHORS ├── mimosa ├── rpc │ ├── samples │ │ ├── .gitignore │ │ ├── CMakeLists.txt │ │ ├── kv-db.proto │ │ ├── kv-db.cc │ │ ├── database.hh │ │ ├── kv-db-http.cc │ │ └── database.cc │ ├── log.cc │ ├── log.hh │ ├── gen │ │ └── CMakeLists.txt │ ├── http-call.hh │ ├── exception.hh │ ├── bencode.hh │ ├── service.cc │ ├── server.cc │ ├── service-map.hh │ ├── server.hh │ ├── json.hh │ ├── service-map.cc │ ├── call.hh │ ├── CMakeLists.txt │ ├── rpc.doch │ ├── service.hh │ ├── http-call.cc │ ├── basic-call.cc │ └── protocol.hh ├── sync.doch ├── string │ ├── tests │ │ └── CMakeLists.txt │ └── CMakeLists.txt ├── format │ ├── tests │ │ ├── CMakeLists.txt │ │ ├── tst-format.cc │ │ └── tst-print.cc │ ├── CMakeLists.txt │ ├── format.hh │ ├── format-stream.hh │ ├── format.doch │ └── print.hh ├── redis │ ├── redis.hh │ ├── log.cc │ ├── log.hh │ ├── CMakeLists.txt │ ├── reply.hh │ └── context.hh ├── http │ ├── .gitignore │ ├── tests │ │ └── CMakeLists.txt │ ├── cookie.cc │ ├── docs.txt │ ├── log.cc │ ├── http.doch │ ├── log.hh │ ├── request-reader.cc │ ├── redirect.hh │ ├── time.hh │ ├── byte-range.hh │ ├── request-reader.hh │ ├── redirect.cc │ ├── response-reader.hh │ ├── response-writer.cc │ ├── response-reader.cc │ ├── response-writer.hh │ ├── log-handler.hh │ ├── samples │ │ ├── CMakeLists.txt │ │ ├── mget.cc │ │ ├── mput.cc │ │ └── mpost.cc │ ├── mime-db.hh │ ├── coding.hh │ ├── handler.hh │ ├── time.cc │ ├── error-handler.cc │ ├── error-handler.hh │ ├── log-handler.cc │ ├── request-writer.hh │ ├── chunked-stream.hh │ ├── method.hh │ ├── host-handler.cc │ ├── dispatch-handler.cc │ ├── host-handler.hh │ ├── dispatch-handler.hh │ ├── method.cc │ ├── message-reader.hh │ ├── request-writer.cc │ ├── server.hh │ └── client-channel.cc ├── fft │ ├── scwf-gen.cc │ ├── normalize.hh │ ├── fft.hh │ ├── normalize.hxx │ ├── scwf-gen.hh │ └── fft.hxx ├── smtp │ ├── sample │ │ ├── CMakeLists.txt │ │ └── msendmail.cc │ ├── CMakeLists.txt │ ├── mail.hh │ ├── client.hh │ └── mail.cc ├── tpl │ ├── tests │ │ └── CMakeLists.txt │ ├── log.cc │ ├── log.hh │ ├── ast │ │ ├── text.cc │ │ ├── text.hh │ │ ├── root.hh │ │ ├── var.hh │ │ ├── empty.hh │ │ ├── repeated.hh │ │ ├── root.cc │ │ ├── empty.cc │ │ ├── repeated.cc │ │ ├── node.hh │ │ └── var.cc │ ├── map.hh │ ├── cache.hh │ ├── cache.cc │ ├── include.hh │ ├── value.hh │ ├── template.hh │ ├── abstract-value.cc │ ├── template.doch │ ├── parser.hh │ ├── filter-factory.hh │ ├── CMakeLists.txt │ ├── include.cc │ ├── append-helper.hh │ ├── value.hxx │ ├── list.cc │ ├── abstract-value.hh │ ├── list.hh │ ├── dict.hh │ ├── template.cc │ └── dict.cc ├── uptime.hh ├── init.hh ├── log │ ├── tests │ │ ├── CMakeLists.txt │ │ └── hello-log.cc │ ├── CMakeLists.txt │ ├── level.hh │ └── log.hh ├── options │ ├── CMakeLists.txt │ └── tests │ │ ├── CMakeLists.txt │ │ ├── duplicate-opts.cc │ │ └── hello-opts.cc ├── net │ ├── CMakeLists.txt │ ├── common.hh │ ├── accept.hh │ ├── print.hh │ ├── accept.cc │ ├── print.cc │ ├── io.hh │ ├── connect.hh │ └── server.hh ├── json │ ├── tests │ │ └── CMakeLists.txt │ ├── CMakeLists.txt │ └── encoder.hh ├── env.hh ├── yield.hh ├── fs │ ├── exists.hh │ ├── fs.doch │ ├── copy.hh │ ├── move.hh │ ├── rm.hh │ ├── exists.cc │ ├── CMakeLists.txt │ ├── find.hh │ ├── move.cc │ ├── copy.cc │ ├── dir-iterator.hh │ ├── find.cc │ ├── dir-iterator.cc │ └── rm.cc ├── uri │ ├── tests │ │ ├── CMakeLists.txt │ │ ├── tst-percent-encoding.cc │ │ └── tst-normalize-path.cc │ ├── scheme.hh │ ├── normalize-path.hh │ ├── parse-query.hh │ ├── CMakeLists.txt │ ├── percent-encoding.hh │ └── tools │ │ └── gen-percent-encoding-tables.cc ├── cpu-count.hh ├── kvs.hh ├── uptime.cc ├── tests │ ├── CMakeLists.txt │ ├── tst-cache.cc │ ├── tst-ref-countable.cc │ └── tst-container-of.cc ├── stream │ ├── copy.hh │ ├── tests │ │ ├── CMakeLists.txt │ │ ├── lzma-decoder.cc │ │ ├── lzma-encoder.cc │ │ ├── tst-html-escape.cc │ │ └── tst-filters.cc │ ├── lzma-decoder.cc │ ├── lzma-encoder.cc │ ├── lzma-decoder.hh │ ├── lzma-encoder.hh │ ├── html-escape.hh │ ├── CMakeLists.txt │ ├── base16-decoder.hh │ ├── fd-stream.hh │ ├── percent-encoder.hh │ ├── lzma.hh │ ├── filter.cc │ ├── base64-decoder.hh │ ├── base16-encoder.hh │ ├── filter.hxx │ ├── limited-stream.hh │ ├── fd-stream.cc │ ├── string-stream.cc │ ├── percent-encoder.cc │ ├── tls-stream.hh │ ├── filter.hh │ ├── tee-stream.hh │ ├── copy.cc │ ├── string-stream.hh │ ├── limited-stream.cc │ ├── net-fd-stream.hh │ ├── buffer.cc │ ├── direct-fd-stream.hh │ ├── buffer.hh │ └── tee-stream.cc ├── non-movable.hh ├── flat │ └── CMakeLists.txt ├── compat │ └── uio.hh ├── git │ ├── revwalk.cc │ ├── archive.hh │ ├── revwalk.hh │ ├── patch.hh │ ├── blob.hh │ ├── diff.hh │ ├── tag.hh │ ├── tree-entry.hh │ ├── repository.hh │ ├── CMakeLists.txt │ ├── tree.hh │ ├── commit.hh │ ├── reference.hh │ ├── repository.cc │ ├── reference.cc │ └── tree.cc ├── sqlite │ └── CMakeLists.txt ├── env.cc ├── preproc.hh ├── bencode │ ├── CMakeLists.txt │ ├── copy.hh │ ├── encoder.hh │ ├── decoder.hh │ ├── encoder.cc │ └── bencode.doch ├── cpu-count.cc ├── cpu-foreach.hh ├── locker.hh ├── non-copyable.hh ├── archive │ └── CMakeLists.txt ├── priviledge-drop.hh ├── bittorrent │ ├── CMakeLists.txt │ └── torrent-descriptor.hh ├── function.hh ├── shared-locker.hh ├── spin-lock.hxx ├── singleton.hh ├── singleton.hxx ├── container-of.hh ├── init.doch ├── endian.hh ├── thread-pool.cc ├── thread-pool.hh ├── init.cc ├── spin-lock.hh ├── future.hh ├── thread.hh ├── unique-locker.hh ├── cpu-foreach.hxx └── intrusive-hash-table.hh ├── cmake ├── Tests.cmake ├── Bison.cmake ├── Flex.cmake └── ProtocMimosa.cmake ├── tasks.org ├── dist.sh ├── README └── LICENSE /ChangeLog: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /MIMOSA_VERSION: -------------------------------------------------------------------------------- 1 | 0.9.0 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | build-clang 3 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Alexandre Bique 2 | -------------------------------------------------------------------------------- /mimosa/rpc/samples/.gitignore: -------------------------------------------------------------------------------- 1 | kv-db.pb.cc 2 | kv-db.pb.h 3 | -------------------------------------------------------------------------------- /mimosa/sync.doch: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | @defgroup Sync Synchronization 4 | 5 | */ 6 | -------------------------------------------------------------------------------- /mimosa/string/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mimosa_test(mimosa-string tst-string-ref.cc) 2 | -------------------------------------------------------------------------------- /mimosa/format/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mimosa_test(mimosa-format tst-format.cc tst-print.cc) 2 | -------------------------------------------------------------------------------- /mimosa/redis/redis.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "reply.hh" 4 | # include "context.hh" 5 | 6 | -------------------------------------------------------------------------------- /mimosa/http/.gitignore: -------------------------------------------------------------------------------- 1 | request-lexer.cc 2 | request-lexer.hh 3 | request-parser.hh 4 | request-parser.cc 5 | -------------------------------------------------------------------------------- /mimosa/fft/scwf-gen.cc: -------------------------------------------------------------------------------- 1 | #include "scwf-gen.hh" 2 | 3 | int main(int argc, char **argv) 4 | { 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /mimosa/smtp/sample/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(msendmail msendmail.cc) 2 | target_link_libraries(msendmail mimosa-smtp) -------------------------------------------------------------------------------- /mimosa/tpl/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mimosa_test(mimosa-tpl tst-tpl.cc) 2 | target_link_libraries(tst-mimosa-tpl mimosa-tpl) 3 | -------------------------------------------------------------------------------- /mimosa/uptime.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "time.hh" 4 | 5 | namespace mimosa 6 | { 7 | Time uptime() noexcept; 8 | } 9 | -------------------------------------------------------------------------------- /mimosa/init.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mimosa 4 | { 5 | void init(int argc, char ** argv); 6 | void deinit(); 7 | } 8 | 9 | -------------------------------------------------------------------------------- /mimosa/log/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(hello-log EXCLUDE_FROM_ALL hello-log.cc) 2 | target_link_libraries(hello-log mimosa) 3 | -------------------------------------------------------------------------------- /mimosa/options/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install(FILES 2 | options.hh 3 | DESTINATION include/mimosa/options/) 4 | 5 | add_subdirectory(tests) 6 | -------------------------------------------------------------------------------- /mimosa/string/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install(FILES 2 | string-ref.hh 3 | DESTINATION include/mimosa/string/) 4 | 5 | add_subdirectory(tests) 6 | -------------------------------------------------------------------------------- /mimosa/http/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mimosa_test(mimosa-http tst-response.cc tst-request-parser.cc) 2 | target_link_libraries(tst-mimosa-http mimosa-http) 3 | -------------------------------------------------------------------------------- /mimosa/net/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install(FILES 2 | accept.hh 3 | connect.hh 4 | io.hh 5 | print.hh 6 | server.hh 7 | DESTINATION include/mimosa/net/) 8 | -------------------------------------------------------------------------------- /mimosa/json/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mimosa_test(mimosa-json 2 | tst-decoder.cc 3 | tst-encoder.cc 4 | ) 5 | 6 | target_link_libraries(tst-mimosa-json mimosa-json) -------------------------------------------------------------------------------- /mimosa/log/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install(FILES 2 | level.hh 3 | log.hh 4 | origin.hh 5 | DESTINATION include/mimosa/log/) 6 | 7 | add_subdirectory(tests) 8 | -------------------------------------------------------------------------------- /mimosa/env.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mimosa 6 | { 7 | void setenv(const std::string &key, const std::string &value); 8 | } 9 | -------------------------------------------------------------------------------- /mimosa/http/cookie.cc: -------------------------------------------------------------------------------- 1 | #include "cookie.hh" 2 | 3 | namespace mimosa 4 | { 5 | namespace http 6 | { 7 | Cookie::Cookie() = default; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /mimosa/yield.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mimosa 6 | { 7 | inline void yield() noexcept 8 | { 9 | ::sched_yield(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /mimosa/rpc/log.cc: -------------------------------------------------------------------------------- 1 | #include "log.hh" 2 | 3 | namespace mimosa 4 | { 5 | namespace rpc 6 | { 7 | log::Origin *rpc_log = new log::Origin("rpc", log::kInfo); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /mimosa/fs/exists.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mimosa 6 | { 7 | namespace fs 8 | { 9 | bool exists(const std::string &path); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /mimosa/http/docs.txt: -------------------------------------------------------------------------------- 1 | http header fields rfc: http://tools.ietf.org/html/rfc4229 2 | http 1.1 rfc: http://tools.ietf.org/html/rfc2616 3 | http state management: http://tools.ietf.org/html/rfc2965 4 | -------------------------------------------------------------------------------- /mimosa/http/log.cc: -------------------------------------------------------------------------------- 1 | #include "log.hh" 2 | 3 | namespace mimosa 4 | { 5 | namespace http 6 | { 7 | log::Origin *http_log = new log::Origin("http", log::kInfo); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /mimosa/redis/log.cc: -------------------------------------------------------------------------------- 1 | #include "log.hh" 2 | 3 | namespace mimosa 4 | { 5 | namespace redis 6 | { 7 | log::Origin * redis_log = new log::Origin("redis", log::kWarning); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /mimosa/tpl/log.cc: -------------------------------------------------------------------------------- 1 | #include "log.hh" 2 | 3 | namespace mimosa 4 | { 5 | namespace tpl 6 | { 7 | log::Origin * tpl_log = new log::Origin("template", log::kWarning); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /mimosa/redis/log.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "../log/log.hh" 4 | 5 | namespace mimosa 6 | { 7 | namespace redis 8 | { 9 | extern log::Origin * redis_log; 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /mimosa/tpl/log.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../log/log.hh" 4 | 5 | namespace mimosa 6 | { 7 | namespace tpl 8 | { 9 | extern mimosa::log::Origin * tpl_log; 10 | } 11 | } 12 | 13 | -------------------------------------------------------------------------------- /mimosa/uri/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mimosa_test(mimosa-uri 2 | tst-normalize-path.cc 3 | tst-parse-query.cc 4 | tst-percent-encoding.cc 5 | tst-url.cc) 6 | target_link_libraries(tst-mimosa-uri mimosa-uri) 7 | -------------------------------------------------------------------------------- /mimosa/cpu-count.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mimosa 6 | { 7 | /** 8 | * @return the number of available CPU 9 | */ 10 | size_t cpuCount() noexcept; 11 | } 12 | 13 | -------------------------------------------------------------------------------- /mimosa/fs/fs.doch: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | @defgroup Fs File system 4 | 5 | This module regroups file system related helpers. 6 | 7 | */ 8 | 9 | namespace mimosa 10 | { 11 | /** @ingroup Fs */ 12 | namespace fs {} 13 | } 14 | -------------------------------------------------------------------------------- /mimosa/format/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install(FILES 2 | print.hh 3 | print.hxx 4 | format.hh 5 | format.hxx 6 | format.doch 7 | format-stream.hh 8 | DESTINATION include/mimosa/format/) 9 | 10 | add_subdirectory(tests) 11 | -------------------------------------------------------------------------------- /mimosa/http/http.doch: -------------------------------------------------------------------------------- 1 | /** 2 | 3 | @defgroup Http Http 4 | 5 | This module provides classes to work with the HTTP protocol, both server 6 | and client side. 7 | 8 | */ 9 | 10 | /** @ingroup Http */ 11 | namespace http {} 12 | -------------------------------------------------------------------------------- /mimosa/kvs.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | # include 5 | 6 | namespace mimosa 7 | { 8 | // XXX remove me 9 | typedef std::unordered_multimap kvs; 10 | } 11 | 12 | -------------------------------------------------------------------------------- /mimosa/uptime.cc: -------------------------------------------------------------------------------- 1 | #include "uptime.hh" 2 | 3 | namespace mimosa 4 | { 5 | Time uptime() noexcept 6 | { 7 | static const Time start = monotonicTimeCoarse(); 8 | return monotonicTimeCoarse() - start; 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /mimosa/uri/scheme.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mimosa 4 | { 5 | namespace uri 6 | { 7 | enum Scheme { 8 | kSchemeUnknown, 9 | kSchemeHttp, 10 | kSchemeHttps, 11 | }; 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /mimosa/fs/copy.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mimosa 6 | { 7 | namespace fs 8 | { 9 | bool copyFile(const std::string &src, 10 | const std::string &dst); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /mimosa/fs/move.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mimosa 6 | { 7 | namespace fs 8 | { 9 | bool moveFile(const std::string &src, 10 | const std::string &dst); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /mimosa/fft/normalize.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mimosa { 4 | namespace fft { 5 | 6 | template 7 | void normalizeEuclide(fp_type *spectrum); 8 | 9 | } 10 | } 11 | 12 | #include "normalize.hxx" 13 | -------------------------------------------------------------------------------- /mimosa/http/log.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../log/log.hh" 4 | 5 | namespace mimosa 6 | { 7 | namespace http 8 | { 9 | /** 10 | * @ingroup Http 11 | */ 12 | extern log::Origin * http_log; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mimosa/net/common.hh: -------------------------------------------------------------------------------- 1 | #include "../preproc.hh" 2 | 3 | #ifdef MIMOSA_WIN 4 | # include 5 | # include 6 | #endif 7 | 8 | #ifdef MIMOSA_UNIX 9 | # include 10 | # include 11 | #endif 12 | -------------------------------------------------------------------------------- /mimosa/rpc/log.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../log/log.hh" 4 | 5 | namespace mimosa 6 | { 7 | namespace rpc 8 | { 9 | /** 10 | * @ingroup Http 11 | */ 12 | extern log::Origin * rpc_log; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /mimosa/redis/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install(FILES 2 | context.hh 3 | log.hh 4 | redis.hh 5 | reply.hh 6 | DESTINATION include/mimosa/redis/) 7 | 8 | add_library(mimosa-redis STATIC log.cc) 9 | target_link_libraries(mimosa-redis PUBLIC mimosa) 10 | -------------------------------------------------------------------------------- /mimosa/options/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(hello-opts EXCLUDE_FROM_ALL hello-opts.cc) 2 | target_link_libraries(hello-opts mimosa) 3 | 4 | add_executable(duplicate-opts EXCLUDE_FROM_ALL duplicate-opts.cc) 5 | target_link_libraries(duplicate-opts mimosa) 6 | -------------------------------------------------------------------------------- /mimosa/http/request-reader.cc: -------------------------------------------------------------------------------- 1 | #include "request-reader.hh" 2 | #include "server-channel.hh" 3 | #include "message-reader.hxx" 4 | 5 | namespace mimosa 6 | { 7 | namespace http 8 | { 9 | template class MessageReader; 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /mimosa/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mimosa_test(mimosa 2 | 3 | # containers 4 | tst-cache.cc 5 | tst-intrusive-dlist.cc 6 | tst-intrusive-hash-table.cc 7 | tst-trie.cc 8 | 9 | tst-ref-countable.cc 10 | tst-string-ref.cc 11 | tst-container-of.cc 12 | ) 13 | -------------------------------------------------------------------------------- /mimosa/stream/copy.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "stream.hh" 4 | 5 | namespace mimosa 6 | { 7 | namespace stream 8 | { 9 | int64_t copy(Stream & input, 10 | Stream & output, 11 | int64_t max_bytes = 0); 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /mimosa/fs/rm.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | 5 | namespace mimosa 6 | { 7 | namespace fs 8 | { 9 | bool rm(const std::string & path, 10 | bool recursive = false, 11 | bool force = false); 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /mimosa/rpc/gen/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_executable(protoc-gen-mimosa protoc-gen-mimosa.cc) 2 | target_link_libraries(protoc-gen-mimosa protoc PkgConfig::protobuf pthread z) 3 | 4 | install(TARGETS protoc-gen-mimosa 5 | RUNTIME DESTINATION bin 6 | LIBRARY DESTINATION lib 7 | ARCHIVE DESTINATION lib) 8 | -------------------------------------------------------------------------------- /mimosa/net/accept.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # 4 | 5 | #include 6 | 7 | #include "../time.hh" 8 | 9 | namespace mimosa 10 | { 11 | namespace net 12 | { 13 | int accept(int socket, ::sockaddr * address, socklen_t * address_len, 14 | Time timeout); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /mimosa/non-movable.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mimosa 4 | { 5 | class NonMovable 6 | { 7 | protected: 8 | constexpr NonMovable() noexcept = default; 9 | 10 | inline NonMovable(NonMovable &&) = delete; 11 | inline NonMovable & operator=(NonMovable&&) = delete; 12 | }; 13 | } 14 | -------------------------------------------------------------------------------- /mimosa/rpc/http-call.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "json.hh" 4 | 5 | namespace mimosa 6 | { 7 | namespace rpc 8 | { 9 | bool httpCall(const std::string &url, 10 | const google::protobuf::Message &request, 11 | google::protobuf::Message *response); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /mimosa/http/redirect.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | 5 | # include "response-writer.hh" 6 | 7 | namespace mimosa 8 | { 9 | namespace http 10 | { 11 | /** 12 | * @ingroup Http 13 | */ 14 | bool redirect(ResponseWriter & response, const std::string & location); 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /mimosa/uri/normalize-path.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | # include 5 | 6 | namespace mimosa 7 | { 8 | namespace uri 9 | { 10 | void normalizePath(const char * input, 11 | uint32_t len, 12 | std::string * output); 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /mimosa/flat/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install(FILES 2 | flat.hh 3 | DESTINATION include/mimosa/flat/) 4 | 5 | add_library(mimosa-flat STATIC flat.cc) 6 | target_link_libraries(mimosa-flat PUBLIC mimosa) 7 | 8 | install(TARGETS mimosa-flat 9 | RUNTIME DESTINATION bin 10 | LIBRARY DESTINATION lib 11 | ARCHIVE DESTINATION lib) 12 | -------------------------------------------------------------------------------- /mimosa/http/time.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | # include 5 | 6 | namespace mimosa 7 | { 8 | namespace http 9 | { 10 | /** 11 | * @ingroup Http 12 | */ 13 | std::string time(::time_t t = ::time(nullptr)); 14 | 15 | ::time_t time(const std::string & str); 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /mimosa/compat/uio.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #if defined(__unix__) || defined(__APPLE__) || defined(__HAIKU__) 7 | # include 8 | #else 9 | # define IOV_MAX 128 10 | struct iovec { 11 | void *iov_base = nullptr; 12 | uint64_t iov_len = 0; 13 | }; 14 | #endif 15 | -------------------------------------------------------------------------------- /mimosa/fft/fft.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mimosa { 4 | namespace fft { 5 | 6 | template 7 | void fft(const fp_type *signal, fp_type *spectrum); 8 | 9 | template 10 | void ifft(const fp_type *spectrum, fp_type *signal); 11 | 12 | } 13 | } 14 | 15 | #include "fft.hxx" 16 | -------------------------------------------------------------------------------- /mimosa/fs/exists.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "exists.hh" 6 | 7 | namespace mimosa 8 | { 9 | namespace fs 10 | { 11 | bool exists(const std::string &path) 12 | { 13 | struct ::stat st; 14 | return ::stat(path.c_str(), &st) == 0; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /cmake/Tests.cmake: -------------------------------------------------------------------------------- 1 | add_custom_target(check) 2 | 3 | macro(mimosa_test MODULE) 4 | add_executable(tst-${MODULE} EXCLUDE_FROM_ALL ${ARGN}) 5 | target_link_libraries(tst-${MODULE} gtest_main gtest mimosa) 6 | add_custom_target(run-tst-${MODULE} ./tst-${MODULE} DEPENDS tst-${MODULE}) 7 | add_dependencies(check run-tst-${MODULE}) 8 | endmacro(mimosa_test) 9 | -------------------------------------------------------------------------------- /mimosa/git/revwalk.cc: -------------------------------------------------------------------------------- 1 | #include "revwalk.hh" 2 | 3 | namespace mimosa 4 | { 5 | namespace git 6 | { 7 | Revwalk::Revwalk(git_repository * repo) 8 | : walk_(nullptr) 9 | { 10 | git_revwalk_new(&walk_, repo); 11 | } 12 | 13 | Revwalk::~Revwalk() 14 | { 15 | git_revwalk_free(walk_); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mimosa/http/byte-range.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mimosa 4 | { 5 | namespace http 6 | { 7 | struct ByteRange 8 | { 9 | enum Type { 10 | kStart, 11 | kRange, 12 | kSuffix 13 | }; 14 | 15 | enum Type type_; 16 | int64_t start_; 17 | int64_t end_; 18 | }; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /mimosa/rpc/exception.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mimosa 4 | { 5 | namespace rpc 6 | { 7 | class MissingRequiredField 8 | { 9 | }; 10 | 11 | class InvalidFormat 12 | { 13 | }; 14 | 15 | class FieldAlreadySet 16 | { 17 | }; 18 | 19 | class InvalidEnumValue 20 | { 21 | }; 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /mimosa/rpc/bencode.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | # include 5 | 6 | # include "../bencode/encoder.hh" 7 | 8 | namespace mimosa 9 | { 10 | namespace rpc 11 | { 12 | void encode(bencode::Encoder & enc, 13 | const google::protobuf::Message * msg); 14 | } 15 | } 16 | 17 | -------------------------------------------------------------------------------- /mimosa/sqlite/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install(FILES 2 | sqlite.hh 3 | sqlite.hxx 4 | DESTINATION include/mimosa/sqlite) 5 | 6 | add_library(mimosa-sqlite STATIC sqlite.cc) 7 | target_link_libraries(mimosa-sqlite PUBLIC mimosa) 8 | 9 | install(TARGETS mimosa-sqlite 10 | RUNTIME DESTINATION bin 11 | LIBRARY DESTINATION lib 12 | ARCHIVE DESTINATION lib) 13 | -------------------------------------------------------------------------------- /mimosa/git/archive.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "../archive/writer.hh" 4 | # include "tree.hh" 5 | 6 | namespace mimosa 7 | { 8 | namespace git 9 | { 10 | bool gitArchive(Tree & tree, 11 | mimosa::archive::Writer & archive, 12 | const std::string & prefix = ""); 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /mimosa/http/request-reader.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "request.hh" 4 | # include "message-reader.hh" 5 | 6 | namespace mimosa 7 | { 8 | namespace http 9 | { 10 | class ServerChannel; 11 | typedef MessageReader RequestReader; 12 | extern template class MessageReader; 13 | } 14 | } 15 | 16 | -------------------------------------------------------------------------------- /mimosa/http/redirect.cc: -------------------------------------------------------------------------------- 1 | #include "response-writer.hh" 2 | #include "redirect.hh" 3 | 4 | namespace mimosa 5 | { 6 | namespace http 7 | { 8 | bool redirect(ResponseWriter & response, const std::string & location) 9 | { 10 | response.setStatus(kStatusFound); 11 | response.setLocation(location); 12 | return true; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mimosa/env.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "env.hh" 4 | 5 | namespace mimosa 6 | { 7 | void setenv(const std::string &key, const std::string &value) 8 | { 9 | #if defined(__unix__) || defined(__APPLE__) 10 | ::setenv(key.c_str(), value.c_str(), true); 11 | #elif defined(__WIN32__) 12 | _putenv_s(key.c_str(), value.c_str()); 13 | #endif 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /mimosa/stream/tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mimosa_test(mimosa-stream 2 | tst-filters.cc 3 | tst-hash.cc 4 | tst-html-escape.cc) 5 | 6 | add_executable(lzma-encoder EXCLUDE_FROM_ALL lzma-encoder.cc) 7 | target_link_libraries(lzma-encoder mimosa lzma) 8 | 9 | add_executable(lzma-decoder EXCLUDE_FROM_ALL lzma-decoder.cc) 10 | target_link_libraries(lzma-decoder mimosa lzma) 11 | -------------------------------------------------------------------------------- /mimosa/tpl/ast/text.cc: -------------------------------------------------------------------------------- 1 | #include "text.hh" 2 | 3 | namespace mimosa 4 | { 5 | namespace tpl 6 | { 7 | namespace ast 8 | { 9 | void 10 | Text::execute(stream::Stream::Ptr stream, 11 | const AbstractValue & /*value*/) const 12 | { 13 | stream->write(text_.data(), text_.size()); 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /tasks.org: -------------------------------------------------------------------------------- 1 | * DONE bench http performances with http://code.google.com/p/httperf/ 2 | CLOSED: [2012-02-09 Thu 23:59] 3 | * DONE implement chunked output in request writer 4 | CLOSED: [2011-12-12 Mon 15:01] 5 | * template cache: add a file template cache which invalidate entries with inotify 6 | * DONE http: fix a bug with post containing & 7 | CLOSED: [2012-02-09 Thu 23:59] 8 | -------------------------------------------------------------------------------- /cmake/Bison.cmake: -------------------------------------------------------------------------------- 1 | macro(mimosa_bison name) 2 | add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${name}.hh ${CMAKE_CURRENT_SOURCE_DIR}/${name}.cc 3 | COMMAND bison --output=${CMAKE_CURRENT_SOURCE_DIR}/${name}.cc 4 | ${CMAKE_CURRENT_SOURCE_DIR}/${name}.y 5 | DEPENDS ${name}.y 6 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) 7 | endmacro(mimosa_bison) 8 | -------------------------------------------------------------------------------- /mimosa/preproc.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #if defined(__linux) || defined(__linux__) 4 | # define MIMOSA_LINUX 5 | # define MIMOSA_UNIX 6 | #elif defined(__APPLE__) 7 | # define MIMOSA_MAC 8 | # define MIMOSA_UNIX 9 | #elif defined(__unix__) || defined(__HAIKU__) 10 | # define MIMOSA_HAIKU 11 | # define MIMOSA_UNIX 12 | #elif defined(__WIN32__) 13 | # define MIMOSA_WIN 14 | #endif 15 | -------------------------------------------------------------------------------- /mimosa/http/response-reader.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "response.hh" 4 | # include "message-reader.hh" 5 | 6 | namespace mimosa 7 | { 8 | namespace http 9 | { 10 | class ClientChannel; 11 | class Request; 12 | 13 | typedef MessageReader ResponseReader; 14 | extern template class MessageReader; 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /mimosa/git/revwalk.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | 5 | namespace mimosa 6 | { 7 | namespace git 8 | { 9 | class Revwalk 10 | { 11 | public: 12 | explicit Revwalk(git_repository *repo); 13 | ~Revwalk(); 14 | 15 | inline operator git_revwalk *() { return walk_; } 16 | 17 | private: 18 | git_revwalk *walk_; 19 | }; 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /mimosa/smtp/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install(FILES 2 | client.hh 3 | mail.hh 4 | DESTINATION include/mimosa/smtp/) 5 | 6 | add_library(mimosa-smtp STATIC 7 | client.cc 8 | mail.cc) 9 | target_link_libraries(mimosa-smtp PUBLIC mimosa) 10 | 11 | install(TARGETS mimosa-smtp 12 | RUNTIME DESTINATION bin 13 | LIBRARY DESTINATION lib 14 | ARCHIVE DESTINATION lib) 15 | 16 | add_subdirectory(sample) 17 | -------------------------------------------------------------------------------- /mimosa/uri/parse-query.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | # include 5 | 6 | # include "../kvs.hh" 7 | 8 | namespace mimosa 9 | { 10 | namespace uri 11 | { 12 | /** @warning parseQuery does not url decode */ 13 | void parseQuery(const char * input, 14 | uint32_t len, 15 | kvs * kvs); 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /mimosa/stream/lzma-decoder.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "lzma-decoder.hh" 4 | 5 | namespace mimosa 6 | { 7 | namespace stream 8 | { 9 | LzmaDecoder::LzmaDecoder(Stream::Ptr stream, uint64_t memlimit, uint32_t flags) 10 | : Lzma(std::move(stream)) 11 | { 12 | if (lzma_auto_decoder(&lzma_, memlimit, flags) != LZMA_OK) 13 | assert(false); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /mimosa/stream/lzma-encoder.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "lzma-encoder.hh" 4 | 5 | namespace mimosa 6 | { 7 | namespace stream 8 | { 9 | LzmaEncoder::LzmaEncoder(Stream::Ptr stream, uint32_t preset, lzma_check check) 10 | : Lzma(std::move(stream)) 11 | { 12 | if (lzma_easy_encoder(&lzma_, preset, check) != LZMA_OK) 13 | assert(false); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /mimosa/json/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install(FILES 2 | decoder.hh 3 | encoder.hh 4 | DESTINATION include/mimosa/json/) 5 | 6 | add_library(mimosa-json STATIC 7 | encoder.cc 8 | decoder.cc 9 | ) 10 | target_link_libraries(mimosa-json PUBLIC mimosa) 11 | 12 | install(TARGETS mimosa-json 13 | RUNTIME DESTINATION bin 14 | LIBRARY DESTINATION lib 15 | ARCHIVE DESTINATION lib) 16 | 17 | add_subdirectory(tests) 18 | -------------------------------------------------------------------------------- /mimosa/bencode/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install(FILES 2 | copy.hh 3 | decoder.hh 4 | encoder.hh 5 | DESTINATION include/mimosa/bencode/) 6 | 7 | add_library(mimosa-bencode STATIC 8 | copy.cc 9 | decoder.cc 10 | encoder.cc 11 | ) 12 | target_link_libraries(mimosa-bencode PUBLIC mimosa) 13 | 14 | install(TARGETS mimosa-bencode 15 | RUNTIME DESTINATION bin 16 | LIBRARY DESTINATION lib 17 | ARCHIVE DESTINATION lib) 18 | -------------------------------------------------------------------------------- /mimosa/cpu-count.cc: -------------------------------------------------------------------------------- 1 | #if __WIN32__ 2 | # include 3 | #endif 4 | 5 | #include 6 | 7 | #include "cpu-count.hh" 8 | 9 | namespace mimosa 10 | { 11 | size_t cpuCount() noexcept 12 | { 13 | #ifdef __WIN32__ 14 | SYSTEM_INFO info; 15 | GetSystemInfo(&info); 16 | return info.dwNumberOfProcessors; 17 | #else 18 | return static_cast(sysconf(_SC_NPROCESSORS_ONLN)); 19 | #endif 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /mimosa/tpl/map.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | 5 | namespace mimosa 6 | { 7 | namespace tpl 8 | { 9 | template 10 | class Value : public AbstractValue 11 | { 12 | public: 13 | virtual void write(const StringRef & var, 14 | stream::Stream::Ptr stream); 15 | 16 | std::unordered_map values_; 17 | }; 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /mimosa/fs/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install(FILES 2 | copy.hh 3 | dir-iterator.hh 4 | exists.hh 5 | find.hh 6 | move.hh 7 | rm.hh 8 | DESTINATION include/mimosa/fs/) 9 | 10 | add_library(mimosa-fs STATIC 11 | copy.cc 12 | dir-iterator.cc 13 | exists.cc 14 | find.cc 15 | move.cc 16 | rm.cc 17 | ) 18 | 19 | install(TARGETS mimosa-fs 20 | RUNTIME DESTINATION bin 21 | LIBRARY DESTINATION lib 22 | ARCHIVE DESTINATION lib) 23 | -------------------------------------------------------------------------------- /mimosa/uri/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install(FILES 2 | normalize-path.hh 3 | parse-query.hh 4 | percent-encoding.hh 5 | scheme.hh 6 | url.hh 7 | DESTINATION include/mimosa/uri/) 8 | 9 | add_library(mimosa-uri STATIC url.cc) 10 | target_link_libraries(mimosa-uri PUBLIC mimosa) 11 | 12 | add_subdirectory(tests) 13 | 14 | install(TARGETS mimosa-uri 15 | RUNTIME DESTINATION bin 16 | LIBRARY DESTINATION lib 17 | ARCHIVE DESTINATION lib) 18 | -------------------------------------------------------------------------------- /cmake/Flex.cmake: -------------------------------------------------------------------------------- 1 | macro(mimosa_flex name) 2 | add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${name}.hh ${CMAKE_CURRENT_SOURCE_DIR}/${name}.cc 3 | COMMAND flex --outfile=${CMAKE_CURRENT_SOURCE_DIR}/${name}.cc 4 | --header-file=${CMAKE_CURRENT_SOURCE_DIR}/${name}.hh 5 | ${CMAKE_CURRENT_SOURCE_DIR}/${name}.l 6 | DEPENDS ${name}.l 7 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) 8 | endmacro(mimosa_flex) 9 | -------------------------------------------------------------------------------- /mimosa/http/response-writer.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "response-writer.hh" 5 | #include "server-channel.hh" 6 | #include "chunked-stream.hh" 7 | #include "../format/print.hh" 8 | #include "../stream/zlib-encoder.hh" 9 | #include "log.hh" 10 | #include "message-writer.hxx" 11 | 12 | namespace mimosa 13 | { 14 | namespace http 15 | { 16 | template class MessageWriter; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mimosa/cpu-foreach.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mimosa 6 | { 7 | /** 8 | * Will create one thread for each cpu, set the cpu affinity 9 | * and execute cb. 10 | * 11 | * Thread created in cb will by default keep the same cpu affinity. 12 | */ 13 | template 14 | void cpuForeach(const Callback& cb, bool affinity = false, size_t ratio = 1); 15 | } 16 | 17 | #include "cpu-foreach.hxx" -------------------------------------------------------------------------------- /mimosa/stream/lzma-decoder.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "lzma.hh" 4 | 5 | namespace mimosa 6 | { 7 | namespace stream 8 | { 9 | class LzmaDecoder : public Lzma 10 | { 11 | public: 12 | MIMOSA_DEF_PTR(LzmaDecoder); 13 | 14 | explicit LzmaDecoder(Stream::Ptr stream, 15 | uint64_t memlimit = UINT64_MAX, 16 | uint32_t flags = 0); 17 | }; 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /mimosa/net/print.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #if defined(__unix__) || defined(__APPLE__) || defined(__HAIKU__) 6 | # include 7 | # include 8 | #endif 9 | 10 | #ifdef __WIN32__ 11 | # include 12 | #endif 13 | 14 | #include 15 | 16 | namespace mimosa 17 | { 18 | namespace net 19 | { 20 | std::string print(const struct ::sockaddr *addr, ::socklen_t len); 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /mimosa/stream/lzma-encoder.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "lzma.hh" 4 | 5 | namespace mimosa 6 | { 7 | namespace stream 8 | { 9 | class LzmaEncoder : public Lzma 10 | { 11 | public: 12 | MIMOSA_DEF_PTR(LzmaEncoder); 13 | 14 | explicit LzmaEncoder(Stream::Ptr stream, 15 | uint32_t preset = 5, 16 | lzma_check check = LZMA_CHECK_CRC64); 17 | }; 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /mimosa/locker.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "non-copyable.hh" 4 | #include "non-movable.hh" 5 | 6 | namespace mimosa 7 | { 8 | /** 9 | * @ingroup Sync 10 | */ 11 | template 12 | class Locker : private NonCopyable, private NonMovable 13 | { 14 | public: 15 | inline explicit Locker(T & mutex) : mutex_(mutex) { mutex_.lock(); } 16 | inline ~Locker() { mutex_.unlock(); } 17 | private: 18 | T & mutex_; 19 | }; 20 | } 21 | 22 | -------------------------------------------------------------------------------- /mimosa/rpc/service.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "service.hh" 4 | 5 | namespace mimosa 6 | { 7 | namespace rpc 8 | { 9 | Service::CallMethodStatus 10 | Service::callMethod(BasicCall::Ptr /*call*/, 11 | const char * /*request_data*/, 12 | uint32_t /*request_size*/) 13 | { 14 | assert(false && "should not get called!"); 15 | return kNotImplemented; 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mimosa/stream/html-escape.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "filter.hh" 4 | 5 | namespace mimosa 6 | { 7 | namespace stream 8 | { 9 | class HtmlEscape : public Filter 10 | { 11 | public: 12 | MIMOSA_DEF_PTR(HtmlEscape); 13 | 14 | explicit HtmlEscape(Stream::Ptr stream); 15 | 16 | virtual int64_t write(const char * data, uint64_t nbytes); 17 | virtual int64_t read(char * data, uint64_t nbytes); 18 | }; 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /mimosa/net/accept.cc: -------------------------------------------------------------------------------- 1 | #include "common.hh" 2 | 3 | #include "io.hh" 4 | #include "accept.hh" 5 | 6 | namespace mimosa 7 | { 8 | namespace net 9 | { 10 | int accept(int socket, struct sockaddr * address, socklen_t * address_len, 11 | Time timeout) 12 | { 13 | if (!waitForFdReady(socket, POLLIN | POLLRDNORM | POLLRDBAND | POLLPRI, timeout)) 14 | return -1; 15 | return ::accept(socket, address, address_len); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /mimosa/git/patch.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mimosa 4 | { 5 | namespace git 6 | { 7 | class Patch 8 | { 9 | public: 10 | inline explicit Patch(git_patch * patch = nullptr) : patch_(patch) {} 11 | inline ~Patch() { git_patch_free(patch_); } 12 | 13 | inline operator git_patch *() { return patch_; } 14 | inline git_patch ** ref() { return &patch_; } 15 | 16 | private: 17 | git_patch * patch_; 18 | }; 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /mimosa/http/response-reader.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "response-reader.hh" 5 | #include "server-channel.hh" 6 | #include "chunked-stream.hh" 7 | #include "../format/print.hh" 8 | #include "../stream/zlib-encoder.hh" 9 | #include "log.hh" 10 | #include "client-channel.hh" 11 | #include "message-reader.hxx" 12 | 13 | namespace mimosa 14 | { 15 | namespace http 16 | { 17 | template class MessageReader; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /mimosa/stream/tests/lzma-decoder.cc: -------------------------------------------------------------------------------- 1 | #include "../copy.hh" 2 | #include "../fd-stream.hh" 3 | #include "../lzma-decoder.hh" 4 | 5 | int main(int argc, char **argv) 6 | { 7 | mimosa::stream::Stream::Ptr in = new mimosa::stream::FdStream(0); 8 | mimosa::stream::Stream::Ptr out = new mimosa::stream::FdStream(1); 9 | mimosa::stream::Stream::Ptr lzma = new mimosa::stream::LzmaDecoder(out); 10 | 11 | mimosa::stream::copy(*in, *lzma); 12 | lzma->flush(); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /mimosa/stream/tests/lzma-encoder.cc: -------------------------------------------------------------------------------- 1 | #include "../copy.hh" 2 | #include "../fd-stream.hh" 3 | #include "../lzma-encoder.hh" 4 | 5 | int main(int argc, char **argv) 6 | { 7 | mimosa::stream::Stream::Ptr in = new mimosa::stream::FdStream(0); 8 | mimosa::stream::Stream::Ptr out = new mimosa::stream::FdStream(1); 9 | mimosa::stream::Stream::Ptr lzma = new mimosa::stream::LzmaEncoder(out); 10 | 11 | mimosa::stream::copy(*in, *lzma); 12 | lzma->flush(); 13 | return 0; 14 | } 15 | -------------------------------------------------------------------------------- /mimosa/tpl/ast/text.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "../../string-ref.hh" 4 | # include "node.hh" 5 | 6 | namespace mimosa 7 | { 8 | namespace tpl 9 | { 10 | namespace ast 11 | { 12 | class Text : public Node 13 | { 14 | public: 15 | virtual void execute(stream::Stream::Ptr stream, 16 | const AbstractValue & value) const; 17 | 18 | 19 | StringRef text_; 20 | }; 21 | } 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /mimosa/non-copyable.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mimosa 4 | { 5 | class NonCopyable 6 | { 7 | protected: 8 | constexpr NonCopyable() noexcept = default; 9 | 10 | // allow move stuff 11 | inline NonCopyable(NonCopyable &&) noexcept {} 12 | inline NonCopyable & operator=(NonCopyable&&) noexcept { return *this; } 13 | 14 | private: 15 | NonCopyable(const NonCopyable &) = delete; 16 | NonCopyable & operator=(const NonCopyable &) = delete; 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /mimosa/fft/normalize.hxx: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #include "normalize.hh" 6 | 7 | namespace mimosa { 8 | namespace fft { 9 | 10 | template 11 | void normalizeEuclide(fp_type *spectrum) 12 | { 13 | fp_type norm = 0; 14 | 15 | for (int i = 0; i < len; ++i) 16 | norm += spectrum[i] * spectrum[i]; 17 | norm = std::sqrt(norm); 18 | 19 | for (int i = 0; i < len; ++i) 20 | spectrum[i] /= norm; 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /mimosa/fft/scwf-gen.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "fft.hh" 4 | 5 | template 6 | void generateIdealSawSpectrum(fp_type *spectrum); 7 | 8 | template 9 | void generateIdealSawSignal(fp_type *signal); 10 | 11 | template 12 | void generateIdealSquareSpectrum(fp_type *spectrum); 13 | 14 | template 15 | void generateIdealSquareSignal(fp_type *signal); 16 | 17 | #include "scwf-gen.hxx" 18 | -------------------------------------------------------------------------------- /mimosa/options/tests/duplicate-opts.cc: -------------------------------------------------------------------------------- 1 | /* 2 | * This test is meant to check that having two time the same option 3 | * will generate a failure. 4 | */ 5 | 6 | #include "../options.hh" 7 | 8 | bool * enable_x = mimosa::options::addSwitch("group", "enable-x", "enables feature x"); 9 | bool * enable_y = mimosa::options::addSwitch("group", "enable-x", "enables feature x"); 10 | 11 | int main(int argc, char ** argv) 12 | { 13 | mimosa::options::parse(argc, argv); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /mimosa/archive/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | pkg_check_modules(LibArchive REQUIRED IMPORTED_TARGET libarchive) 2 | 3 | add_library(mimosa-archive STATIC 4 | reader.cc 5 | writer.cc) 6 | 7 | install(FILES 8 | entry.hh 9 | reader.hh 10 | writer.hh 11 | DESTINATION include/mimosa/archive/) 12 | 13 | target_link_libraries(mimosa-archive PUBLIC mimosa PkgConfig::LibArchive) 14 | 15 | install(TARGETS mimosa-archive 16 | RUNTIME DESTINATION bin 17 | LIBRARY DESTINATION lib 18 | ARCHIVE DESTINATION lib) 19 | -------------------------------------------------------------------------------- /mimosa/git/blob.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | 5 | namespace mimosa 6 | { 7 | namespace git 8 | { 9 | class Blob 10 | { 11 | public: 12 | inline explicit Blob(git_blob * blob = nullptr) : blob_(blob) {} 13 | inline ~Blob() { git_blob_free(blob_); } 14 | 15 | inline operator git_blob *() { return blob_; } 16 | inline git_blob ** ref() { return &blob_; } 17 | 18 | private: 19 | git_blob * blob_; 20 | }; 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /mimosa/git/diff.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | 5 | namespace mimosa 6 | { 7 | namespace git 8 | { 9 | class Diff 10 | { 11 | public: 12 | inline explicit Diff(git_diff * diff = nullptr) : diff_(diff) {} 13 | inline ~Diff() { git_diff_free(diff_); } 14 | 15 | inline operator git_diff *() { return diff_; } 16 | inline git_diff ** ref() { return &diff_; } 17 | 18 | private: 19 | git_diff * diff_; 20 | }; 21 | } 22 | } 23 | 24 | -------------------------------------------------------------------------------- /mimosa/rpc/samples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | mimosa_protoc(kv-db) 2 | 3 | add_library(rpc-kv-db-proto kv-db.pb.cc) 4 | 5 | add_executable(rpc-kv-db kv-db.cc database.cc) 6 | target_link_libraries(rpc-kv-db PUBLIC rpc-kv-db-proto mimosa-rpc) 7 | 8 | add_executable(rpc-kv-client kv-db-client.cc) 9 | target_link_libraries(rpc-kv-client PUBLIC rpc-kv-db-proto mimosa-rpc) 10 | 11 | # add_executable(rpc-kv-db-http kv-db-http.cc database.cc) 12 | # target_link_libraries(rpc-kv-db-http rpc-kv-db-proto mimosa-rpc-http) 13 | -------------------------------------------------------------------------------- /mimosa/http/response-writer.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "../stream/stream.hh" 4 | # include "../stream/direct-fd-stream.hh" 5 | # include "../stream/buffer.hh" 6 | # include "response.hh" 7 | # include "message-writer.hh" 8 | 9 | namespace mimosa 10 | { 11 | namespace http 12 | { 13 | class ServerChannel; 14 | class Request; 15 | 16 | typedef MessageWriter ResponseWriter; 17 | extern template class MessageWriter; 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /mimosa/priviledge-drop.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | 5 | namespace mimosa 6 | { 7 | bool priviledgeDrop(const std::string & chroot, 8 | const std::string & user, 9 | const std::string & group); 10 | 11 | /** 12 | * This function registers options for chroot and userid/groupid. 13 | * 14 | * When you call it, it will check if we are root, and then chroot 15 | * and change user/group. 16 | */ 17 | bool priviledgeDrop(); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /mimosa/net/print.cc: -------------------------------------------------------------------------------- 1 | #if defined(__unix__) || defined(__APPLE__) 2 | # include 3 | #endif 4 | 5 | #ifdef __WIN32__ 6 | # include 7 | #endif 8 | 9 | #include "print.hh" 10 | 11 | namespace mimosa 12 | { 13 | namespace net 14 | { 15 | std::string print(const struct ::sockaddr *addr, ::socklen_t len) 16 | { 17 | char host[80] = { '\0' }; 18 | 19 | getnameinfo(addr, len, host, sizeof (host), nullptr, 0, NI_NUMERICHOST); 20 | return host; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /mimosa/git/tag.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | 5 | # include "../non-copyable.hh" 6 | 7 | namespace mimosa 8 | { 9 | namespace git 10 | { 11 | class Tag : public NonCopyable 12 | { 13 | public: 14 | inline Tag() : tag_(nullptr) {} 15 | inline ~Tag() { git_tag_free(tag_); } 16 | 17 | inline operator git_tag *() const { return tag_; } 18 | inline git_tag ** ref() { return &tag_; } 19 | 20 | private: 21 | git_tag * tag_; 22 | }; 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /mimosa/git/tree-entry.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mimosa 4 | { 5 | namespace git 6 | { 7 | class TreeEntry 8 | { 9 | public: 10 | inline explicit TreeEntry(git_tree_entry * entry = nullptr) : entry_(entry) {} 11 | inline ~TreeEntry() { git_tree_entry_free(entry_); } 12 | 13 | inline operator git_tree_entry *() { return entry_; } 14 | inline git_tree_entry ** ref() { return &entry_; } 15 | 16 | private: 17 | git_tree_entry * entry_; 18 | }; 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /mimosa/smtp/mail.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | # include 5 | 6 | namespace mimosa 7 | { 8 | namespace smtp 9 | { 10 | struct Mail 11 | { 12 | std::string data() const; 13 | 14 | std::vector to; 15 | std::vector cc; 16 | std::vector bcc; 17 | std::string from; 18 | std::string reply_to; 19 | std::string subject; 20 | std::string date; 21 | std::string content; 22 | }; 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /mimosa/bittorrent/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install(FILES 2 | torrent-descriptor.hh 3 | torrent-parser.hh 4 | DESTINATION include/mimosa/bittorrent/) 5 | 6 | add_library(mimosa-bittorrent STATIC 7 | torrent-descriptor.cc 8 | torrent-descriptor.hh 9 | torrent-parser.cc 10 | torrent-parser.hh 11 | ) 12 | target_link_libraries(mimosa-bittorrent PUBLIC 13 | mimosa-bencode 14 | mimosa) 15 | 16 | install(TARGETS mimosa-bittorrent 17 | RUNTIME DESTINATION bin 18 | LIBRARY DESTINATION lib 19 | ARCHIVE DESTINATION lib) 20 | -------------------------------------------------------------------------------- /mimosa/http/log-handler.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "handler.hh" 4 | 5 | namespace mimosa 6 | { 7 | namespace http 8 | { 9 | /** 10 | * @ingroup Http 11 | */ 12 | class LogHandler : public Handler 13 | { 14 | public: 15 | virtual bool handle(RequestReader & request, ResponseWriter & response) const; 16 | 17 | inline void setHandler(Handler::ConstPtr handler) { handler_ = handler; } 18 | 19 | private: 20 | Handler::ConstPtr handler_; 21 | }; 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /mimosa/git/repository.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | # include 5 | 6 | # include 7 | 8 | namespace mimosa 9 | { 10 | namespace git 11 | { 12 | class Repository 13 | { 14 | public: 15 | explicit Repository(const std::string & repo_path); 16 | ~Repository(); 17 | 18 | inline operator git_repository * () const { return repo_; } 19 | 20 | int64_t lastCommitTime() const; 21 | 22 | private: 23 | git_repository *repo_; 24 | }; 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /mimosa/tpl/cache.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../expiring-cache.hh" 4 | #include "template.hh" 5 | 6 | namespace mimosa 7 | { 8 | namespace tpl 9 | { 10 | class Cache : public mimosa::ExpiringCache 11 | { 12 | public: 13 | Cache(); 14 | virtual ~Cache() = default; 15 | 16 | protected: 17 | virtual void cacheMiss(const std::string & key); 18 | }; 19 | } 20 | } 21 | 22 | extern template class mimosa::ExpiringCache; 23 | 24 | -------------------------------------------------------------------------------- /mimosa/function.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | 5 | # include "ref-countable.hh" 6 | # include "non-copyable.hh" 7 | 8 | namespace mimosa 9 | { 10 | template 11 | class Function : public std::function, 12 | public RefCountable >, 13 | private NonCopyable 14 | { 15 | public: 16 | inline Function(std::function && fct) 17 | : std::function(fct) 18 | { 19 | } 20 | 21 | inline Function() {} 22 | }; 23 | } 24 | 25 | -------------------------------------------------------------------------------- /cmake/ProtocMimosa.cmake: -------------------------------------------------------------------------------- 1 | macro(mimosa_protoc name) 2 | add_custom_command(OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/${name}.pb.h ${CMAKE_CURRENT_SOURCE_DIR}/${name}.pb.cc 3 | COMMAND protoc --plugin=$ --mimosa_out=. ${name}.proto 4 | DEPENDS protoc-gen-mimosa ${name}.proto 5 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) 6 | set_source_files_properties( 7 | ${CMAKE_CURRENT_SOURCE_DIR}/${name}.pb.h 8 | ${CMAKE_CURRENT_SOURCE_DIR}/${name}.pb.cc 9 | PROPERTIES GENERATED true) 10 | endmacro(mimosa_protoc) 11 | -------------------------------------------------------------------------------- /mimosa/net/io.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../compat/uio.hh" 4 | 5 | #include "../time.hh" 6 | 7 | namespace mimosa 8 | { 9 | namespace net 10 | { 11 | bool waitForFdReady(int fd, int events, Time timeout); 12 | 13 | int64_t write(int fd, const char * data, uint64_t nbytes, Time timeout); 14 | int64_t writev(int fd, const ::iovec *iov, int iovcnt, Time timeout); 15 | int64_t read(int fd, char * data, uint64_t nbytes, Time timeout); 16 | int64_t readv(int fd, const ::iovec *iov, int iovcnt, Time timeout); 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /dist.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | VERSION=$($DISTDIR.tar.xz 25 | rm -rf $DISTDIR 26 | 27 | md5sum $DISTDIR.tar.xz >$DISTDIR.tar.xz.md5sum 28 | -------------------------------------------------------------------------------- /mimosa/format/tests/tst-format.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "../format.hh" 4 | 5 | namespace mimosa 6 | { 7 | namespace format 8 | { 9 | namespace 10 | { 11 | TEST(Format, Simple) 12 | { 13 | EXPECT_EQ("1", str("1")); 14 | EXPECT_EQ("42", str("%v", 42)); 15 | EXPECT_EQ("42", str("%", 42)); 16 | EXPECT_EQ("42", str("%d", 42)); 17 | EXPECT_EQ("2a", str("%x", 42)); 18 | EXPECT_EQ("2a", str("%x", 42)); 19 | EXPECT_EQ("%", str("%%", 42)); 20 | } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /mimosa/http/samples/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_custom_target(key.pem certtool -p --outfile key.pem) 2 | add_custom_target(cert.pem certtool -s --load-privkey key.pem --outfile cert.pem 3 | DEPENDS key.pem) 4 | 5 | add_executable(web-server web-server.cc) 6 | target_link_libraries(web-server mimosa-http) 7 | 8 | add_executable(mget mget.cc) 9 | target_link_libraries(mget mimosa-http) 10 | 11 | add_executable(mput mput.cc) 12 | target_link_libraries(mput mimosa-flat mimosa-http) 13 | 14 | add_executable(mpost mpost.cc) 15 | target_link_libraries(mpost mimosa-flat mimosa-http) 16 | -------------------------------------------------------------------------------- /mimosa/fs/find.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | # include 5 | # include 6 | 7 | namespace mimosa 8 | { 9 | namespace fs 10 | { 11 | /** 12 | * @ingroup Fs 13 | * @param cb return false to break the loop 14 | * @param max_depth the maximum depth 15 | */ 16 | void 17 | find(const std::string & root, 18 | uint32_t max_depth, 19 | const std::function &cb); 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /mimosa/options/tests/hello-opts.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "../options.hh" 4 | 5 | bool * enable_x = mimosa::options::addSwitch("group", "enable-x", "enables feature x"); 6 | std::string * toto = mimosa::options::addOption( 7 | "group2", "toto", "toto's name", "(unamed toto)"); 8 | 9 | int main(int argc, char ** argv) 10 | { 11 | mimosa::options::parse(argc, argv); 12 | 13 | std::cout << "feature x " << (*enable_x ? "enabled" : "disabled") << std::endl; 14 | std::cout << "toto's name: " << *toto << std::endl; 15 | 16 | return 0; 17 | } 18 | -------------------------------------------------------------------------------- /mimosa/shared-locker.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "non-copyable.hh" 4 | #include "non-movable.hh" 5 | 6 | namespace mimosa 7 | { 8 | /** 9 | * @ingroup Sync 10 | */ 11 | template 12 | class SharedLocker : private NonCopyable, private NonMovable 13 | { 14 | public: 15 | 16 | inline SharedLocker(T & rwlock) 17 | : rwlock_(rwlock) 18 | { 19 | rwlock_.sharedLock(); 20 | } 21 | 22 | inline ~SharedLocker() 23 | { 24 | rwlock_.unlock(); 25 | } 26 | 27 | private: 28 | T & rwlock_; 29 | }; 30 | } 31 | 32 | -------------------------------------------------------------------------------- /mimosa/spin-lock.hxx: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mimosa 4 | { 5 | inline 6 | SpinLock::~SpinLock() noexcept 7 | { 8 | /* wait for unlock */ 9 | while (lock_) 10 | ; 11 | } 12 | 13 | inline void 14 | SpinLock::lock() noexcept 15 | { 16 | while (!__sync_bool_compare_and_swap(&lock_, 0, 1)) 17 | ; 18 | } 19 | 20 | inline bool 21 | SpinLock::tryLock() noexcept 22 | { 23 | return __sync_bool_compare_and_swap(&lock_, 0, 1); 24 | } 25 | 26 | inline void 27 | SpinLock::unlock() noexcept 28 | { 29 | lock_ = 0; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /mimosa/rpc/samples/kv-db.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package mimosa.rpc.samples.pb; 4 | 5 | enum Status 6 | { 7 | kOk = 0; 8 | kNotFound = 1; 9 | kInternalError = 2; 10 | } 11 | 12 | message Key 13 | { 14 | bytes key = 1; 15 | } 16 | 17 | message KeyValue 18 | { 19 | bytes key = 1; 20 | bytes value = 2; 21 | } 22 | 23 | message Result 24 | { 25 | Status status = 1; 26 | bytes value = 2; 27 | } 28 | 29 | service Database 30 | { 31 | rpc get(Key) returns (Result); 32 | rpc set(KeyValue) returns (Result); 33 | rpc del(Key) returns (Result); 34 | } 35 | -------------------------------------------------------------------------------- /mimosa/tpl/cache.cc: -------------------------------------------------------------------------------- 1 | #include "cache.hh" 2 | #include "../expiring-cache.hxx" // contains template definition 3 | 4 | namespace mimosa 5 | { 6 | namespace tpl 7 | { 8 | Cache::Cache() 9 | { 10 | setEntryTimeout(minute * 15); 11 | setValueTimeout(hour); 12 | setCleanupPeriod(minute); 13 | startCleanupThread(); 14 | } 15 | 16 | void 17 | Cache::cacheMiss(const std::string & key) 18 | { 19 | set(key, Template::parseFile(key)); 20 | } 21 | } 22 | } 23 | 24 | template class mimosa::ExpiringCache; 25 | -------------------------------------------------------------------------------- /mimosa/singleton.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mimosa 6 | { 7 | /** 8 | * @warning NOT THREAD SAFE, you need to manualy call release to ensure 9 | * resources liberation. 10 | * 11 | * Helpers to implement a singleton. 12 | * Though, you should follow the @ref initialisation rule. 13 | */ 14 | template 15 | class Singleton 16 | { 17 | public: 18 | static T & instance(); 19 | static void release(); 20 | 21 | protected: 22 | static std::atomic instance_; 23 | }; 24 | } 25 | 26 | # include "singleton.hxx" 27 | 28 | -------------------------------------------------------------------------------- /mimosa/stream/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install(FILES 2 | base16-decoder.hh 3 | base16-encoder.hh 4 | base64-decoder.hh 5 | buffered-stream.hh 6 | buffer.hh 7 | copy.hh 8 | direct-fd-stream.hh 9 | fd-stream.hh 10 | filter.hh 11 | filter.hxx 12 | hash.hh 13 | html-escape.hh 14 | limited-stream.hh 15 | lzma.hh 16 | lzma-decoder.hh 17 | lzma-encoder.hh 18 | net-fd-stream.hh 19 | percent-encoder.hh 20 | stream.hh 21 | string-stream.hh 22 | tee-stream.hh 23 | tls-stream.hh 24 | zlib-encoder.hh 25 | DESTINATION include/mimosa/stream/) 26 | 27 | add_subdirectory(tests) 28 | -------------------------------------------------------------------------------- /mimosa/http/mime-db.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | # include 5 | 6 | # include "../non-copyable.hh" 7 | 8 | namespace mimosa 9 | { 10 | namespace http 11 | { 12 | /** 13 | * @ingroup Http 14 | */ 15 | class MimeDb : private NonCopyable 16 | { 17 | public: 18 | static MimeDb & instance(); 19 | 20 | std::string mimeType(const std::string & filename); 21 | 22 | private: 23 | MimeDb(); 24 | 25 | void load(); 26 | 27 | std::unordered_map mime_types_; 28 | }; 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /mimosa/format/format.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mimosa { namespace format { 6 | inline std::ostream &format(std::ostream &os, const char *fmt); 7 | 8 | template 9 | inline std::ostream &format(std::ostream &os, const char *fmt, const T &value, Args... args); 10 | 11 | template 12 | inline std::string str(const char *fmt, Args... args) { 13 | std::ostringstream os; 14 | format(os, fmt, args...); 15 | return os.str(); 16 | } 17 | }} // namespace mimosa::format 18 | 19 | #include "format.hxx" 20 | -------------------------------------------------------------------------------- /mimosa/git/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | install(FILES 2 | archive.hh 3 | blob.hh 4 | commit.hh 5 | diff.hh 6 | patch.hh 7 | reference.hh 8 | repository.hh 9 | revwalk.hh 10 | tag.hh 11 | tree-entry.hh 12 | tree.hh 13 | DESTINATION include/mimosa/git/) 14 | 15 | add_library(mimosa-git STATIC 16 | archive.cc 17 | reference.cc 18 | repository.cc 19 | revwalk.cc 20 | tree.cc 21 | ) 22 | 23 | target_link_libraries(mimosa-git PUBLIC 24 | mimosa-archive 25 | mimosa) 26 | 27 | install(TARGETS mimosa-git 28 | RUNTIME DESTINATION bin 29 | LIBRARY DESTINATION lib 30 | ARCHIVE DESTINATION lib) 31 | -------------------------------------------------------------------------------- /mimosa/http/coding.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace mimosa 4 | { 5 | namespace http 6 | { 7 | /** 8 | * @ingroup Http 9 | */ 10 | enum Coding 11 | { 12 | kCodingIdentity = 1 << 0, 13 | kCodingDeflate = 1 << 1, 14 | kCodingGzip = 1 << 2, 15 | kCodingExi = 1 << 3, 16 | kCodingCompress = 1 << 4, 17 | kCodingPack200_gzip = 1 << 5, 18 | kCodingChunked = 1 << 6, 19 | kCodingSdch = 1 << 7, 20 | kCodingZstd = 1 << 8, 21 | kCodingBr = 1 << 9, 22 | }; 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /mimosa/stream/base16-decoder.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "filter.hh" 4 | 5 | namespace mimosa 6 | { 7 | namespace stream 8 | { 9 | class Base16Decoder : public Filter 10 | { 11 | public: 12 | MIMOSA_DEF_PTR(Base16Decoder); 13 | 14 | explicit Base16Decoder(Stream::Ptr stream, const char * base = nullptr); 15 | 16 | virtual int64_t write(const char * data, uint64_t nbytes); 17 | virtual int64_t read(char * data, uint64_t nbytes); 18 | 19 | uint8_t decodeByte(uint8_t c) const; 20 | 21 | private: 22 | const char * base_; 23 | }; 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /mimosa/log/tests/hello-log.cc: -------------------------------------------------------------------------------- 1 | #include "../log.hh" 2 | #include "../../init.hh" 3 | 4 | auto * network = new mimosa::log::Origin("network", mimosa::log::Info); 5 | 6 | int main(int argc, char ** argv) 7 | { 8 | mimosa::init(argc, argv); 9 | 10 | MIMOSA_LOG(Debug, network, "debug message"); 11 | MIMOSA_LOG(Info, network, "info message"); 12 | MIMOSA_LOG(Warning, network, "warning message"); 13 | MIMOSA_LOG(Error, network, "error message"); 14 | MIMOSA_LOG(Critical, network, "critical message"); 15 | MIMOSA_LOG(Fatal, network, "fatal message %d", 1); 16 | 17 | mimosa::deinit(); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /mimosa/singleton.hxx: -------------------------------------------------------------------------------- 1 | namespace mimosa 2 | { 3 | template 4 | std::atomic Singleton::instance_ = {nullptr}; 5 | 6 | template 7 | T & 8 | Singleton::instance() 9 | { 10 | if (!instance_) { 11 | T *t = new T; 12 | T *n = nullptr; 13 | if (!instance_.compare_exchange_weak(n, t)) 14 | delete t; 15 | } 16 | return *instance_; 17 | } 18 | 19 | template 20 | void 21 | Singleton::release() 22 | { 23 | T *t = instance_; 24 | if (instance_.compare_exchange_strong(t, nullptr)) 25 | delete t; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /mimosa/rpc/server.cc: -------------------------------------------------------------------------------- 1 | #include "../stream/fd-stream.hh" 2 | #include "server.hh" 3 | #include "channel.hh" 4 | 5 | namespace mimosa 6 | { 7 | namespace rpc 8 | { 9 | Server::Server() 10 | = default; 11 | 12 | void 13 | Server::serve(int fd, 14 | const ::sockaddr * /*address*/, 15 | socklen_t /*address_len*/) const 16 | { 17 | stream::FdStream::Ptr stream = new stream::FdStream(fd); 18 | Channel::Ptr channel = new Channel(stream.get(), service_map_); 19 | channel->start(); 20 | channel->wait(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /mimosa/stream/fd-stream.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "buffered-stream.hh" 4 | # include "direct-fd-stream.hh" 5 | 6 | namespace mimosa 7 | { 8 | namespace stream 9 | { 10 | class FdStream : public BufferedStream 11 | { 12 | public: 13 | MIMOSA_DEF_PTR(FdStream); 14 | 15 | explicit FdStream(int fd, uint64_t buffer_size = 64 * 1024, bool own_fd = true); 16 | explicit FdStream(const DirectFdStream::Ptr& stream, uint64_t buffer_size = 64 * 1024); 17 | 18 | static FdStream::Ptr openFile(const char * path, int oflags = O_RDONLY, mode_t mode = 0644); 19 | }; 20 | } 21 | } 22 | 23 | -------------------------------------------------------------------------------- /mimosa/stream/percent-encoder.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "filter.hh" 4 | # include "../uri/percent-encoding.hh" 5 | 6 | namespace mimosa 7 | { 8 | namespace stream 9 | { 10 | class PercentEncoder : public Filter 11 | { 12 | public: 13 | MIMOSA_DEF_PTR(PercentEncoder); 14 | 15 | explicit PercentEncoder(Stream::Ptr stream, uri::EncodingType enc = uri::kRfc3986); 16 | 17 | virtual int64_t write(const char * data, uint64_t nbytes); 18 | virtual int64_t read(char * data, uint64_t nbytes); 19 | 20 | protected: 21 | uri::EncodingType enc_; 22 | }; 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /mimosa/http/handler.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "../ref-countable.hh" 4 | #include "../non-copyable.hh" 5 | #include "../non-movable.hh" 6 | #include "request-reader.hh" 7 | #include "response-writer.hh" 8 | 9 | namespace mimosa 10 | { 11 | namespace http 12 | { 13 | class Request; 14 | 15 | /** 16 | * @ingroup Http 17 | */ 18 | class Handler : public RefCountable, private NonCopyable, private NonMovable 19 | { 20 | public: 21 | virtual ~Handler() {} 22 | virtual bool handle(RequestReader & request, ResponseWriter & response) const = 0; 23 | }; 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /mimosa/net/connect.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | # include 5 | 6 | # include 7 | # include 8 | 9 | # include "../time.hh" 10 | # include "../string-ref.hh" 11 | 12 | namespace mimosa 13 | { 14 | namespace net 15 | { 16 | int connect(int socket, const struct sockaddr *address, 17 | socklen_t address_len, Time timeout = 0); 18 | 19 | int connectToHost(const std::string &host, uint16_t port, Time timeout = 0); 20 | 21 | int connectToUnixSocket(const std::string & path, 22 | Time timeout = 0); 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /mimosa/http/time.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "time.hh" 6 | 7 | namespace mimosa 8 | { 9 | namespace http 10 | { 11 | std::string time(::time_t t) 12 | { 13 | char buffer[64]; 14 | 15 | ctime_r(&t, buffer); // needs at most 26 bytes 16 | buffer[::strlen(buffer) - 1] = '\0'; // remove trailing \n 17 | return buffer; 18 | } 19 | 20 | ::time_t time(const std::string & str) 21 | { 22 | tm tm{}; 23 | 24 | strptime(str.c_str(), "%a %b %d %H:%M:%S %Y", &tm); 25 | return mktime(&tm); // local time 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /mimosa/http/error-handler.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "error-handler.hh" 4 | #include "../format/format-stream.hh" 5 | 6 | namespace mimosa 7 | { 8 | namespace http 9 | { 10 | bool 11 | ErrorHandler::basicResponse(Request & /*request*/, ResponseWriter & response, Status status) 12 | { 13 | response.setStatus(status); 14 | format::format( 15 | response, 16 | "Error %v - %v" 17 | "Error %v - %v", 18 | status, statusToString(status), 19 | status, statusToString(status)); 20 | return true; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /mimosa/tests/tst-cache.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "../expiring-cache.hh" 4 | #include "../expiring-cache.hxx" 5 | 6 | namespace mimosa 7 | { 8 | namespace 9 | { 10 | class MyCache : public ExpiringCache 11 | { 12 | protected: 13 | virtual void cacheMiss(const int & key) 14 | { 15 | set(key, key + 42); 16 | } 17 | }; 18 | 19 | TEST(ExpiringCache, Simple) 20 | { 21 | MyCache cache; 22 | 23 | auto val = cache.get(0); 24 | ASSERT_EQ(val->get(), 42); 25 | 26 | val = cache.get(0); 27 | ASSERT_EQ(val->get(), 42); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /mimosa/tpl/ast/root.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "node.hh" 4 | 5 | namespace mimosa 6 | { 7 | namespace tpl 8 | { 9 | class Template; 10 | 11 | namespace ast 12 | { 13 | class Root : public Node 14 | { 15 | public: 16 | Root(const Template & tpl); 17 | ~Root(); 18 | 19 | virtual void execute(stream::Stream::Ptr stream, 20 | const AbstractValue & value) const; 21 | virtual void addChild(Node * node) { childs_.push(node); } 22 | 23 | const Template & tpl_; 24 | nodes_type childs_; 25 | }; 26 | } 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /mimosa/tpl/ast/var.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | 5 | # include "../../string-ref.hh" 6 | # include "../../stream/stream.hh" 7 | # include "node.hh" 8 | 9 | namespace mimosa 10 | { 11 | namespace tpl 12 | { 13 | namespace ast 14 | { 15 | class Var : public Node 16 | { 17 | public: 18 | virtual void execute(stream::Stream::Ptr stream, 19 | const AbstractValue & value) const; 20 | 21 | virtual StringRef var() const; 22 | 23 | std::vector vars_; 24 | std::vector filters_; 25 | }; 26 | } 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /mimosa/stream/lzma.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | 5 | # include "buffer.hh" 6 | # include "filter.hh" 7 | 8 | namespace mimosa 9 | { 10 | namespace stream 11 | { 12 | class Lzma : public Filter 13 | { 14 | public: 15 | MIMOSA_DEF_PTR(Lzma); 16 | 17 | virtual ~Lzma(); 18 | 19 | virtual int64_t write(const char * data, uint64_t nbytes); 20 | virtual int64_t read(char * data, uint64_t nbytes); 21 | 22 | virtual bool flush(); 23 | 24 | protected: 25 | explicit Lzma(Stream::Ptr stream); 26 | 27 | lzma_stream lzma_; 28 | Buffer buffer_; 29 | }; 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /mimosa/git/tree.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | 5 | # include 6 | 7 | # include 8 | 9 | namespace mimosa 10 | { 11 | namespace git 12 | { 13 | class Tree : private mimosa::NonCopyable 14 | { 15 | public: 16 | Tree(git_repository * repo, 17 | const git_oid * oid); 18 | Tree(git_repository * repo, 19 | const git_oid * oid, 20 | const std::string & directory); 21 | ~Tree(); 22 | 23 | inline operator git_tree *() const { return tree_; } 24 | 25 | private: 26 | git_tree * tree_; 27 | }; 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /mimosa/stream/filter.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include "filter.hh" 6 | 7 | namespace mimosa 8 | { 9 | namespace stream 10 | { 11 | Filter::Filter(Stream::Ptr stream) 12 | : stream_(std::move(std::move(stream))) 13 | { 14 | } 15 | 16 | bool 17 | Filter::flush() 18 | { 19 | return stream_->flush(); 20 | } 21 | 22 | void 23 | Filter::setReadTimeout(Time timeout) 24 | { 25 | stream_->setReadTimeout(timeout); 26 | } 27 | 28 | void 29 | Filter::setWriteTimeout(Time timeout) 30 | { 31 | stream_->setWriteTimeout(timeout); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /mimosa/tpl/include.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "template.hh" 4 | # include "abstract-value.hh" 5 | 6 | namespace mimosa 7 | { 8 | namespace tpl 9 | { 10 | class Include : public AbstractValue 11 | { 12 | public: 13 | MIMOSA_DEF_PTR(Include); 14 | 15 | explicit Include(const std::string & name, Template::ConstPtr tpl); 16 | 17 | virtual const AbstractValue * lookup(const StringRef & var) const; 18 | virtual void write(stream::Stream::Ptr stream) const; 19 | 20 | virtual Iterator::Ptr begin() const; 21 | virtual bool empty() const; 22 | 23 | Template::ConstPtr tpl_; 24 | }; 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /mimosa/rpc/service-map.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | 5 | # include "../ref-countable.hh" 6 | # include "../shared-mutex.hh" 7 | # include "service.hh" 8 | 9 | namespace mimosa 10 | { 11 | namespace rpc 12 | { 13 | class ServiceMap : public RefCountable 14 | { 15 | public: 16 | ~ServiceMap(); 17 | 18 | Service::Ptr find(uint32_t service_id) const; 19 | 20 | void add(const Service::Ptr& service); 21 | void remove(const Service::Ptr& service); 22 | 23 | private: 24 | mutable SharedMutex lock_; 25 | std::map services_; 26 | }; 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /mimosa/http/error-handler.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "handler.hh" 4 | # include "status.hh" 5 | 6 | namespace mimosa 7 | { 8 | namespace http 9 | { 10 | /** 11 | * @ingroup Http 12 | */ 13 | class ErrorHandler : public RefCountable 14 | { 15 | public: 16 | inline virtual ~ErrorHandler() {} 17 | 18 | inline virtual bool handle(Request & request, ResponseWriter & response, Status status) const 19 | { 20 | return basicResponse(request, response, status); 21 | } 22 | 23 | static bool basicResponse(Request & request, ResponseWriter & response, Status status); 24 | }; 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /mimosa/tpl/ast/empty.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "../../string-ref.hh" 4 | # include "node.hh" 5 | 6 | namespace mimosa 7 | { 8 | namespace tpl 9 | { 10 | namespace ast 11 | { 12 | class Empty : public Node 13 | { 14 | public: 15 | ~Empty(); 16 | 17 | virtual void execute(stream::Stream::Ptr stream, 18 | const AbstractValue & value) const; 19 | 20 | virtual void addChild(Node * node) { childs_.push(node); } 21 | virtual StringRef var() const { return var_; } 22 | 23 | StringRef var_; 24 | 25 | nodes_type childs_; 26 | }; 27 | } 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /mimosa/tpl/ast/repeated.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "../../string-ref.hh" 4 | # include "node.hh" 5 | 6 | namespace mimosa 7 | { 8 | namespace tpl 9 | { 10 | namespace ast 11 | { 12 | class Repeated : public Node 13 | { 14 | public: 15 | ~Repeated(); 16 | virtual void execute(stream::Stream::Ptr stream, 17 | const AbstractValue & value) const; 18 | 19 | virtual void addChild(Node * node) { childs_.push(node); } 20 | virtual StringRef var() const { return var_; } 21 | 22 | StringRef var_; 23 | 24 | nodes_type childs_; 25 | }; 26 | } 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /mimosa/http/log-handler.cc: -------------------------------------------------------------------------------- 1 | #include "../net/print.hh" 2 | #include "log.hh" 3 | #include "log-handler.hh" 4 | #include "server-channel.hh" 5 | 6 | namespace mimosa 7 | { 8 | namespace http 9 | { 10 | bool 11 | LogHandler::handle(RequestReader & request, ResponseWriter & response) const 12 | { 13 | http_log->info("%s %s %s:%s", 14 | net::print(request.channel().remoteAddr(), 15 | request.channel().remoteAddrLen()), 16 | methodString(request.method()), request.host(), 17 | request.rawLocation()); 18 | return handler_->handle(request, response); 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /mimosa/container-of.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace mimosa 6 | { 7 | /** 8 | * Returns the address of the object of type T containing the given member at the address u. 9 | */ 10 | template 11 | T * 12 | containerOf(U * u, U T::*Member) noexcept 13 | { 14 | union { 15 | T * obj; 16 | uint8_t * obj2; 17 | }; 18 | union { 19 | U * mb; 20 | uint8_t * mb2; 21 | }; 22 | 23 | obj = nullptr; 24 | mb = &(obj->*Member); 25 | auto offset = mb2 - obj2; 26 | mb = u; 27 | obj2 = mb2 - offset; 28 | return obj; 29 | } 30 | } 31 | 32 | -------------------------------------------------------------------------------- /mimosa/fs/move.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "move.hh" 5 | #include "copy.hh" 6 | #include "rm.hh" 7 | 8 | namespace mimosa 9 | { 10 | namespace fs 11 | { 12 | bool moveFile(const std::string &src, 13 | const std::string &dst) 14 | { 15 | if (!::rename(src.c_str(), dst.c_str())) 16 | return true; 17 | 18 | if (errno == EXDEV) 19 | { 20 | if (!copyFile(src, dst)) 21 | return false; 22 | if (!rm(src, false, true)) { 23 | rm(dst, false, true); 24 | return false; 25 | } 26 | return true; 27 | } 28 | return false; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /mimosa/git/commit.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | 5 | # include "../mimosa/mimosa/non-copyable.hh" 6 | 7 | namespace mimosa 8 | { 9 | namespace git 10 | { 11 | class Commit : public NonCopyable 12 | { 13 | public: 14 | inline Commit() : commit_(nullptr) {} 15 | inline Commit(git_repository *repo, const git_oid *id) { 16 | git_commit_lookup(&commit_, repo, id); 17 | } 18 | inline ~Commit() { git_commit_free(commit_); } 19 | 20 | inline git_commit** ref() { return &commit_; } 21 | inline operator git_commit *() const { return commit_; } 22 | 23 | private: 24 | git_commit *commit_; 25 | }; 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /mimosa/stream/base64-decoder.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "filter.hh" 4 | 5 | namespace mimosa 6 | { 7 | namespace stream 8 | { 9 | class Base64Decoder : public Filter 10 | { 11 | public: 12 | MIMOSA_DEF_PTR(Base64Decoder); 13 | 14 | explicit Base64Decoder(Stream::Ptr stream, const char * base = nullptr); 15 | 16 | virtual int64_t write(const char * data, uint64_t nbytes); 17 | virtual int64_t read(char * data, uint64_t nbytes); 18 | 19 | uint8_t decodeByte(uint8_t c) const; 20 | 21 | private: 22 | const char * base_; 23 | uint8_t buff_[4]; 24 | size_t off_; 25 | uint8_t pad_; 26 | }; 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /mimosa/tpl/ast/root.cc: -------------------------------------------------------------------------------- 1 | #include "root.hh" 2 | 3 | namespace mimosa 4 | { 5 | namespace tpl 6 | { 7 | namespace ast 8 | { 9 | Root::Root(const Template & tpl) 10 | : tpl_(tpl) 11 | { 12 | } 13 | 14 | Root::~Root() 15 | { 16 | while (!childs_.empty()) { 17 | auto child = childs_.front(); 18 | childs_.pop(); 19 | delete child; 20 | } 21 | } 22 | 23 | void 24 | Root::execute(stream::Stream::Ptr stream, 25 | const AbstractValue & value) const 26 | { 27 | for (auto & child : childs_) 28 | child.execute(stream, value); 29 | } 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /mimosa/format/format-stream.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "format.hh" 4 | # include "../stream/stream.hh" 5 | 6 | namespace mimosa 7 | { 8 | namespace format 9 | { 10 | // XXX take a reference to stream, not a refcounted pointer 11 | template 12 | inline 13 | bool format(stream::Stream & stream, 14 | const char * fmt, 15 | Args ... args) 16 | { 17 | std::string str(format::str(fmt, args...)); 18 | if (str.empty()) 19 | return true; 20 | int64_t bytes = stream.loopWrite(str.data(), str.size()); 21 | return static_cast (bytes) == str.size(); 22 | } 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /mimosa/stream/base16-encoder.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "filter.hh" 4 | 5 | namespace mimosa 6 | { 7 | namespace stream 8 | { 9 | class Base16Encoder : public Filter 10 | { 11 | public: 12 | MIMOSA_DEF_PTR(Base16Encoder); 13 | 14 | explicit Base16Encoder(Stream::Ptr stream, bool upper = false); 15 | Base16Encoder(Stream::Ptr stream, const char * base); 16 | 17 | virtual int64_t write(const char * data, uint64_t nbytes); 18 | virtual int64_t read(char * data, uint64_t nbytes); 19 | 20 | static int64_t write(Stream::Ptr stream, const char *data, uint64_t nbytes, bool upper = false); 21 | 22 | private: 23 | const char * base_; 24 | }; 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /mimosa/bencode/copy.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "decoder.hh" 4 | # include "encoder.hh" 5 | 6 | namespace mimosa 7 | { 8 | namespace bencode 9 | { 10 | /** 11 | * @ingroup bencode 12 | * 13 | * @brief copy a value from dec to enc 14 | * @return true if copy succeed, false otherwise 15 | */ 16 | bool copyValue(Decoder & dec, 17 | Encoder & enc); 18 | 19 | /** 20 | * @ingroup bencode 21 | * 22 | * @brief copy the current token to enc 23 | * @return true on success, false otherwise 24 | */ 25 | bool copyToken(Token token, 26 | const Decoder & dec, 27 | Encoder & enc); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /mimosa/rpc/samples/kv-db.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "database.hh" 6 | 7 | using namespace mimosa; 8 | 9 | uint16_t & PORT = *options::addOption("", "port", "the port to use", 4242); 10 | 11 | int main(int argc, char ** argv) 12 | { 13 | mimosa::init(argc, argv); 14 | 15 | rpc::ServiceMap::Ptr service_map = new rpc::ServiceMap; 16 | service_map->add(new rpc::samples::Database); 17 | 18 | rpc::Server::Ptr server = new rpc::Server; 19 | server->setServiceMap(service_map.get()); 20 | server->listenInet4(PORT); 21 | 22 | while (true) 23 | server->serveOne(); 24 | 25 | mimosa::deinit(); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /mimosa/stream/filter.hxx: -------------------------------------------------------------------------------- 1 | #include "string-stream.hh" 2 | 3 | namespace mimosa { namespace stream { 4 | template 5 | inline std::string filter(const char *data, uint64_t nbytes) { 6 | mimosa::stream::StringStream::Ptr s = new mimosa::stream::StringStream; 7 | T filter(s.get()); 8 | filter.write(data, nbytes); 9 | return s->moveStr(); 10 | } 11 | 12 | template 13 | inline std::string filter(const std::string &data) { 14 | return filter(data.data(), data.size()); 15 | } 16 | 17 | template 18 | inline std::string filter(const std::string_view &data) { 19 | return filter(data.data(), data.size()); 20 | } 21 | }} // namespace mimosa::stream 22 | -------------------------------------------------------------------------------- /mimosa/git/reference.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | 5 | # include "../non-copyable.hh" 6 | # include "repository.hh" 7 | 8 | namespace mimosa 9 | { 10 | namespace git 11 | { 12 | class Reference : private NonCopyable 13 | { 14 | public: 15 | inline Reference() : ref_(nullptr) {} 16 | inline ~Reference() { git_reference_free(ref_); } 17 | 18 | inline operator git_reference *() { return ref_; } 19 | inline git_reference ** ref() { return &ref_; } 20 | 21 | private: 22 | git_reference * ref_; 23 | }; 24 | 25 | bool referenceToOid(const Repository & repo, 26 | const std::string & ref, 27 | git_oid * oid); 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /mimosa/tpl/value.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "abstract-value.hh" 4 | 5 | namespace mimosa 6 | { 7 | namespace tpl 8 | { 9 | template 10 | class Value : public AbstractValue 11 | { 12 | public: 13 | MIMOSA_DEF_PTR(Value); 14 | 15 | Value(const std::string & name, 16 | const T & value); 17 | 18 | explicit Value(const T & value); 19 | 20 | virtual const AbstractValue * lookup(const StringRef & var) const; 21 | virtual void write(stream::Stream::Ptr stream) const; 22 | 23 | virtual Iterator::Ptr begin() const; 24 | virtual bool empty() const; 25 | 26 | T value_; 27 | }; 28 | } 29 | } 30 | 31 | # include "value.hxx" 32 | 33 | -------------------------------------------------------------------------------- /mimosa/stream/limited-stream.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "stream.hh" 4 | 5 | namespace mimosa 6 | { 7 | namespace stream 8 | { 9 | class LimitedStream : public Stream 10 | { 11 | public: 12 | MIMOSA_DEF_PTR(LimitedStream); 13 | 14 | explicit LimitedStream(Stream::Ptr stream); 15 | 16 | virtual int64_t write(const char * data, uint64_t nbytes); 17 | virtual int64_t read(char * data, uint64_t nbytes); 18 | 19 | inline void setReadLimit(uint64_t bytes) { rbytes_left_ = bytes; } 20 | inline void setWriteLimit(uint64_t bytes) { wbytes_left_ = bytes; } 21 | 22 | private: 23 | Stream::Ptr stream_; 24 | uint64_t rbytes_left_; 25 | uint64_t wbytes_left_; 26 | }; 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /mimosa/http/request-writer.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "request.hh" 4 | # include "message-writer.hh" 5 | # include "response-reader.hh" 6 | 7 | namespace mimosa 8 | { 9 | namespace http 10 | { 11 | class ClientChannel; 12 | 13 | class RequestWriter : public MessageWriter 14 | { 15 | public: 16 | MIMOSA_DEF_PTR(RequestWriter); 17 | 18 | inline explicit RequestWriter(ClientChannel & channel) 19 | : MessageWriter (channel) 20 | { 21 | } 22 | 23 | bool sendRequest(); 24 | ResponseReader::Ptr response(); 25 | 26 | ResponseReader::Ptr send(); 27 | }; 28 | 29 | extern template class MessageWriter; 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /mimosa/git/repository.cc: -------------------------------------------------------------------------------- 1 | #include "repository.hh" 2 | #include "commit.hh" 3 | 4 | namespace mimosa 5 | { 6 | namespace git 7 | { 8 | Repository::Repository(const std::string & repo_path) 9 | : repo_(nullptr) 10 | { 11 | git_repository_open(&repo_, repo_path.c_str()); 12 | } 13 | 14 | Repository::~Repository() 15 | { 16 | git_repository_free(repo_); 17 | } 18 | 19 | int64_t 20 | Repository::lastCommitTime() const 21 | { 22 | git_oid oid; 23 | if (git_reference_name_to_id(&oid, repo_, "HEAD")) 24 | return 0; 25 | 26 | Commit commit(repo_, &oid); 27 | return static_cast(git_commit_time(commit)) * 1000 28 | + git_commit_time_offset(commit); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /mimosa/uri/percent-encoding.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | # include 5 | 6 | namespace mimosa 7 | { 8 | namespace uri 9 | { 10 | enum EncodingType 11 | { 12 | kRfc2396, // encodes ' ' as '+', decodes '+' as ' ' 13 | kRfc3986, // encodes ' ' as '%20', decodes '+' as '+' 14 | }; 15 | 16 | void percentEncode(const char * input, 17 | uint32_t input_len, 18 | std::string * output, 19 | EncodingType rfc = kRfc3986); 20 | 21 | void percentDecode(const char * input, 22 | uint32_t input_len, 23 | std::string * output, 24 | EncodingType rfc = kRfc3986); 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /mimosa/http/chunked-stream.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "../stream/filter.hh" 4 | # include "../stream/buffered-stream.hh" 5 | 6 | namespace mimosa 7 | { 8 | namespace http 9 | { 10 | class ChunkedStream : public stream::Filter 11 | { 12 | public: 13 | MIMOSA_DEF_PTR(ChunkedStream); 14 | 15 | explicit ChunkedStream(const stream::BufferedStream::Ptr& stream); 16 | 17 | virtual int64_t write(const char * data, uint64_t nbytes) override; 18 | virtual int64_t read(char * data, uint64_t nbytes) override; 19 | 20 | private: 21 | virtual bool readChunkSize(); 22 | 23 | stream::BufferedStream::Ptr stream_; 24 | uint64_t bytes_left_; 25 | bool first_chunk_; 26 | bool eof_; 27 | }; 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /mimosa/rpc/server.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include "../net/server.hh" 4 | # include "service-map.hh" 5 | 6 | namespace mimosa 7 | { 8 | namespace rpc 9 | { 10 | class Server : public net::Server 11 | { 12 | public: 13 | MIMOSA_DEF_PTR(Server); 14 | 15 | Server(); 16 | 17 | inline ServiceMap::ConstPtr serviceMap() const { return service_map_; } 18 | inline void setServiceMap(ServiceMap::ConstPtr service_map) 19 | { service_map_ = service_map; } 20 | 21 | virtual void serve(int fd, 22 | const ::sockaddr * address, 23 | socklen_t address_len) const; 24 | 25 | protected: 26 | ServiceMap::ConstPtr service_map_; 27 | }; 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /mimosa/rpc/json.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | # include 5 | 6 | # include "../json/encoder.hh" 7 | # include "../json/decoder.hh" 8 | 9 | namespace mimosa 10 | { 11 | namespace rpc 12 | { 13 | void jsonEncode(json::Encoder & enc, 14 | const google::protobuf::Message & msg); 15 | 16 | void jsonEncode(stream::Stream::Ptr output, 17 | const google::protobuf::Message & msg); 18 | 19 | void jsonDecode(json::Decoder & dec, 20 | google::protobuf::Message * msg); 21 | 22 | void jsonDecode(stream::Stream::Ptr input, 23 | google::protobuf::Message * msg); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /mimosa/tpl/template.hh: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | # include 4 | 5 | # include "../ref-countable.hh" 6 | # include "ast/root.hh" 7 | 8 | namespace mimosa 9 | { 10 | namespace tpl 11 | { 12 | class Parser; 13 | class Template : public RefCountable