├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── README.md ├── avboost ├── README.md ├── example │ ├── CMakeLists.txt │ ├── autoproxy.cpp │ └── multi_proxychain.cpp └── include │ └── boost │ ├── acceptor_server.hpp │ ├── async_coro_queue.hpp │ ├── async_dir_walk.hpp │ ├── async_foreach.hpp │ ├── avloop.hpp │ ├── avproxy.hpp │ ├── avproxy │ ├── auto_proxychain.hpp │ ├── avproxy.hpp │ ├── detail │ │ ├── connect_condition.hpp │ │ ├── error.hpp │ │ ├── proxy_chain.hpp │ │ ├── proxy_error_mapper.hpp │ │ ├── proxy_http.hpp │ │ ├── proxy_socks5.hpp │ │ ├── proxy_ssl.hpp │ │ └── proxy_tcp.hpp │ ├── proxies.hpp │ └── proxy_connect.hpp │ ├── base64.hpp │ ├── bin_from_hex.hpp │ ├── cfunction.hpp │ ├── hash.hpp │ ├── hash │ ├── adler.hpp │ ├── block_cyphers │ │ ├── basic_shacal.hpp │ │ ├── detail │ │ │ ├── basic_functions.hpp │ │ │ ├── md4_policy.hpp │ │ │ ├── md5_policy.hpp │ │ │ ├── shacal1_policy.hpp │ │ │ ├── shacal2_policy.hpp │ │ │ ├── shacal_functions.hpp │ │ │ ├── shacal_policy.hpp │ │ │ └── threefish_policy.hpp │ │ ├── md4.hpp │ │ ├── md5.hpp │ │ ├── shacal.hpp │ │ ├── shacal1.hpp │ │ ├── shacal2.hpp │ │ └── threefish.hpp │ ├── compute_digest.hpp │ ├── crc.hpp │ ├── cubehash.hpp │ ├── davies_meyer_compressor.hpp │ ├── detail │ │ ├── basic_functions.hpp │ │ ├── cubehash_policy.hpp │ │ ├── exploder.hpp │ │ ├── imploder.hpp │ │ ├── md4_policy.hpp │ │ ├── md5_policy.hpp │ │ ├── primes.hpp │ │ ├── sha1_policy.hpp │ │ ├── sha2_policy.hpp │ │ ├── sha_policy.hpp │ │ ├── state_adder.hpp │ │ └── unbounded_shift.hpp │ ├── digest.hpp │ ├── digest_io.hpp │ ├── md4.hpp │ ├── md5.hpp │ ├── merkle_damgard_block_hash.hpp │ ├── pack.hpp │ ├── sha.hpp │ ├── sha1.hpp │ ├── sha2.hpp │ ├── stream_endian.hpp │ └── stream_preprocessor.hpp │ ├── ietf │ └── README.md │ ├── interthread_stream.hpp │ ├── invoke_wrapper.hpp │ ├── json_parser_read.hpp │ ├── json_parser_write.hpp │ ├── logger.hpp │ ├── multihandler.hpp │ ├── splice_stream.hpp │ ├── stringencodings.hpp │ ├── timedcall.hpp │ └── urlencode.hpp ├── libtianya ├── CMakeLists.txt ├── include │ ├── tianya_context.hpp │ ├── tianya_list.hpp │ └── util.hpp └── src │ ├── tianya_list.cpp │ └── wcwidth.c └── src ├── CMakeLists.txt ├── dpi.manifest ├── kindlesettingdialog.cpp ├── kindlesettingdialog.hpp ├── kindlesettingdialog.ui ├── main.cpp ├── mime ├── CMakeLists.txt ├── include │ ├── emailaddress.h │ ├── mimeattachment.h │ ├── mimebase64encoder.h │ ├── mimebase64formatter.h │ ├── mimebytearrayattachment.h │ ├── mimecontentencoder.h │ ├── mimecontentformatter.h │ ├── mimefile.h │ ├── mimehtml.h │ ├── mimeinlinefile.h │ ├── mimemessage.h │ ├── mimemultipart.h │ ├── mimepart.h │ ├── mimeqpencoder.h │ ├── mimeqpformatter.h │ ├── mimetext.h │ ├── quotedprintable.h │ ├── smtpclient.h │ └── smtpmime_global.h └── src │ ├── emailaddress.cpp │ ├── mimeattachment.cpp │ ├── mimebase64encoder.cpp │ ├── mimebase64formatter.cpp │ ├── mimebytearrayattachment.cpp │ ├── mimecontentencoder.cpp │ ├── mimecontentformatter.cpp │ ├── mimefile.cpp │ ├── mimehtml.cpp │ ├── mimeinlinefile.cpp │ ├── mimemessage.cpp │ ├── mimemultipart.cpp │ ├── mimepart.cpp │ ├── mimeqpencoder.cpp │ ├── mimeqpformatter.cpp │ ├── mimetext.cpp │ ├── quotedprintable.cpp │ └── smtpclient.cpp ├── model ├── tianyamodel.cpp └── tianyamodel.hpp ├── novelviewer.cpp ├── novelviewer.hpp ├── novelviewer.ui ├── resource.h ├── sendprogress.cpp ├── sendprogress.hpp ├── sendprogress.ui ├── smtpclient ├── CMakeLists.txt ├── internet_mail_format.hpp ├── smtp.cpp ├── smtp.hpp └── smtptest.cpp ├── syncobj.cpp ├── syncobj.hpp ├── tianya-radar.desktop ├── tianya.ico ├── tianya.qrc ├── tianya.rc.in ├── tianya.svg ├── tianya_download.cpp ├── tianya_download.hpp ├── tianyawindow.cpp ├── tianyawindow.hpp └── tianyawindow.ui /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | *.o 3 | *.obj 4 | ~* 5 | *.kate-swp 6 | .* 7 | .*/ 8 | tianya.kdev4 9 | !.git* 10 | 11 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "third_party/openssl"] 2 | path = third_party/openssl 3 | url = git://gitcafe.com/microcai/openssl-cmake.git 4 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.30) 2 | set(CMAKE_CXX_STANDARD 20) 3 | 4 | project(tianya) 5 | 6 | SET(CPACK_PACKAGE_VERSION_MAJOR "0") 7 | SET(CPACK_PACKAGE_VERSION_MINOR "1") 8 | SET(CPACK_PACKAGE_VERSION_PATCH "0") 9 | 10 | if(MSVC) 11 | set(Boost_USE_STATIC_LIBS ON) 12 | set(Boost_USE_STATIC_RUNTIME ON) 13 | endif() 14 | 15 | if(WIN32) 16 | add_definitions(-DBOOST_ALL_STATIC_LINK) 17 | add_definitions(-DBOOST_THREAD_USE_LIB) 18 | add_definitions(-DBOOST_FILESYSTEM_STATIC_LINK) 19 | add_definitions(-DBOOST_ALL_STATIC_LINK) 20 | add_definitions(-DWIN32_LEAN_AND_MEAN) 21 | add_definitions(-DNOMINMAX) 22 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 23 | add_definitions(-D_WIN32_WINNT=0x0501) 24 | endif() 25 | 26 | set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") 27 | 28 | if(MSVC) 29 | 30 | 31 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /bigobj /MP") 32 | 33 | #set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT") 34 | set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /ignore:4099 /NODEFAULTLIB:libcmt.lib ") 35 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER} /SAFESEH:NO ") 36 | 37 | endif(MSVC) 38 | 39 | if(WIN32) 40 | add_definitions(-DOPENSSL_NO_ENGINE) 41 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DOPENSSL_NO_ENGINE -DOPENSSL_NO_COMP") 42 | include_directories(third_party/openssl/include) 43 | add_subdirectory(third_party/openssl) 44 | else() 45 | find_package(OpenSSL REQUIRED) 46 | endif() 47 | 48 | find_package(Threads) 49 | find_package(Qt6 REQUIRED COMPONENTS Widgets Network Core) 50 | find_package(Boost CONFIG REQUIRED COMPONENTS regex thread system locale context coroutine date_time) 51 | 52 | qt_standard_project_setup() 53 | 54 | include_directories(${OPENSSL_INCLUDE_DIR}) 55 | link_libraries(${OPENSSL_LIBRARIES}) 56 | link_directories(${Boost_LIBRARY_DIR}) 57 | include_directories(${Boost_INCLUDE_DIR}) 58 | 59 | add_subdirectory(libtianya) 60 | 61 | include_directories(libtianya/include) 62 | include_directories(avboost/include) 63 | 64 | link_directories(${QT_LIB_DIR}) 65 | add_subdirectory(src) 66 | 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tianya 2 | 3 | tianya 是一个专门看 tianya 小说的神器. 当然, 也有下载小说(自动发到 kindle)的神奇功能. 4 | 5 | 6 | -------------------------------------------------------------------------------- /avboost/README.md: -------------------------------------------------------------------------------- 1 | avboost 2 | ======= 3 | 4 | some templates that's very very useful during development. 5 | 6 | avboost 是一些在开发 avplayer 的项目过程中编写的极其有用的方便的小模板工具库的集合. 是对 Boost 库的一个补充. 7 | 8 | 包括但不限于 9 | 10 | 11 | * base64 编解码 12 | * cfunction 封装 boost::funcion 为 C 接口的回调. 13 | * async\_coro\_queue 协程使用的异步列队. 14 | * async\_foreach 协程并发的 for\_each 版本 15 | * async\_dir\_walk 利用协程并发的 for\_each 版本实现的异步文件夹遍历. 16 | * acceptor\_server 一个简单的 accepter 用于接受TCP连接. 17 | * avloop 为 asio 添加 idle 回调. 当 io\_service 没事情干的时候调用回调. 18 | * timedcall 简单的 asio deadline\_timer 封装. 用于延时执行一个任务. 19 | * hash 来自 boost.sandbox 的 哈希编码, 支持 SHA1 MD5 20 | * multihandler 一个回调封装, 用于 指定的回调发生N次后调用真正的回调. 21 | * json\_create\_escapes\_utf8.hpp 在使用 boost 的 json 编码器的时候, 包含这个头文件, 可以让 boost 的 json 编码器输出未经过转码的utf8文本 22 | * urlencode.hpp 用于 url 的编码, 将非允许字符使用 % 编码. 23 | * consolestr.hpp 用于将UTF-8字符串转码为本地控制台的字体编码以输出不乱码. 因 linux 和 windows 的控制台编码不一样而引入 24 | * avproxy.hpp asio 的helper, 用于一行代码完成 dns 解析+主机连接+代理协商 25 | 26 | 27 | avproxy 28 | ======= 29 | 30 | asio based async proxy connector 31 | 32 | avproxy is used to make async connections with or without proxyes in one single line of code. 33 | 34 | avproxy 用于在一行代码之内异步发起通过代理和不通过代理的TCP链接 35 | 36 | avproxy support nested proxy aka proxy behind proxy. 37 | 38 | avproxy 支持代理嵌套,能以“代理套代理”的方式发起链接。 39 | 40 | avproxy is as simple as one line call to avproxy::async\_proxy\_connect. 41 | 42 | avproxy 的使用非常简单,调用 avproxy::async\_proxy\_connect 即可。 43 | 44 | async\_proxyconnect 需要的 proxychain 参数可以使用 avproxy::autoproxychain 自动从环境变量构建 45 | 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /avboost/example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | find_package(Threads) 3 | 4 | add_executable( test1 autoproxy.cpp) 5 | add_executable( test2 multi_proxychain.cpp) 6 | 7 | target_link_libraries( test1 ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) 8 | target_link_libraries( test2 ${Boost_LIBRARIES} ${OPENSSL_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) -------------------------------------------------------------------------------- /avboost/example/autoproxy.cpp: -------------------------------------------------------------------------------- 1 |  2 | /*** 3 | * 4 | * autoproxy.cpp 5 | * 6 | * avproxy 示例 - 使用 avproxy::autoproxychain 自动从 环境变了构建 proxychain 7 | * 8 | */ 9 | 10 | #include "avproxy.hpp" 11 | 12 | 13 | 14 | static void connected(const boost::system::error_code & ec, boost::asio::ip::tcp::socket & msocket) 15 | { 16 | if ( ec ) 17 | std::cout << ec.message() << std::endl; 18 | else 19 | msocket.write_some(boost::asio::buffer(std::string("GET / HTTP/1.1\r\n\r\n"))); 20 | } 21 | 22 | int main() 23 | { 24 | boost::asio::io_service io_service; 25 | boost::asio::ip::tcp::socket msocket(io_service); 26 | 27 | // 支持环境变量 socks5_proxy/ http_proxy 哦! 28 | // avproxy::autoproxychain 构建一个 proxychain 29 | // avproxy::autoproxychain 支持环境变量 socks5_proxy/ http_proxy, 要更精确的控制,请自己构建 30 | // proxychain 做为参数. 31 | avproxy::async_proxy_connect( 32 | avproxy::autoproxychain(io_service, msocket, avproxy::proxy::tcp::query("www.google.com", "81")), 33 | boost::bind(&connected, boost::asio::placeholders::error, boost::ref(msocket)) 34 | ); 35 | io_service.run(); 36 | } -------------------------------------------------------------------------------- /avboost/example/multi_proxychain.cpp: -------------------------------------------------------------------------------- 1 |  2 | /*** 3 | * 4 | * multi_proxychain.cpp 5 | * 6 | * avproxy 示例 - 使用 avproxy::proxychain 进行代理嵌套 7 | * 8 | * 9 | * testclient -> socks5 proxy 10 | * -> http proxy 11 | * -> target host 12 | * 13 | */ 14 | 15 | #include "avproxy.hpp" 16 | 17 | 18 | static void connected(const boost::system::error_code & ec, boost::asio::ip::tcp::socket & msocket) 19 | { 20 | if ( ec ) 21 | std::cout << ec.message() << std::endl; 22 | else 23 | msocket.write_some(boost::asio::buffer(std::string("GET / HTTP/1.1\r\n\r\n"))); 24 | } 25 | 26 | int main() 27 | { 28 | boost::asio::io_service io_service; 29 | boost::asio::ip::tcp::socket msocket(io_service); 30 | 31 | avproxy::proxy_chain proxychain(io_service); 32 | proxychain.add(avproxy::proxy::tcp(msocket, boost::asio::ip::tcp::resolver::query("mysocks5proxy.me", "1080"))); 33 | proxychain.add(avproxy::proxy::socks5(msocket, boost::asio::ip::tcp::resolver::query("myhttpproxy.me", "8080"))); 34 | proxychain.add(avproxy::proxy::http(msocket, boost::asio::ip::tcp::resolver::query("www.google.com", "80"))); 35 | 36 | avproxy::async_proxy_connect( 37 | proxychain, boost::bind(&connected, boost::asio::placeholders::error, boost::ref(msocket)) 38 | ); 39 | io_service.run(); 40 | } -------------------------------------------------------------------------------- /avboost/include/boost/acceptor_server.hpp: -------------------------------------------------------------------------------- 1 |  2 | #pragma once 3 | 4 | #ifdef __llvm__ 5 | #pragma GCC diagnostic ignored "-Wdangling-else" 6 | #endif 7 | 8 | #ifndef AV_ACCEPTOR_SERVER_H 9 | #define AV_ACCEPTOR_SERVER_H 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | namespace boost{ 16 | namespace detail{ 17 | 18 | template 19 | class acceptor_server_op : boost::asio::coroutine 20 | { 21 | boost::asio::io_service & io_service; 22 | boost::shared_ptr > m_acceptor_socket; 23 | boost::shared_ptr > m_client_socket; 24 | ProtocolProcesser protocolprocesser; 25 | void start_accept(){ 26 | io_service.post(boost::asio::detail::bind_handler(*this, boost::system::error_code())); 27 | } 28 | 29 | public: 30 | typedef typename Protocol::endpoint endpoint_type; 31 | 32 | acceptor_server_op(boost::asio::io_service & io, const endpoint_type & endpoint, ProtocolProcesser protocolprocesser_) 33 | :io_service(io), m_acceptor_socket(new boost::asio::basic_socket_acceptor(io, endpoint)), protocolprocesser(protocolprocesser_) 34 | { 35 | start_accept(); 36 | } 37 | 38 | acceptor_server_op(boost::shared_ptr > acceptor_socket, ProtocolProcesser protocolprocesser_) 39 | :io_service(acceptor_socket->get_io_service()), m_acceptor_socket(acceptor_socket), protocolprocesser(protocolprocesser_) 40 | { 41 | start_accept(); 42 | } 43 | 44 | 45 | void operator()(const boost::system::error_code & ec) 46 | { 47 | BOOST_ASIO_CORO_REENTER(this) 48 | { 49 | do{ 50 | m_client_socket.reset(new boost::asio::basic_stream_socket(io_service)); 51 | BOOST_ASIO_CORO_YIELD m_acceptor_socket->async_accept(*m_client_socket, *this); 52 | if (!ec) 53 | BOOST_ASIO_CORO_FORK acceptor_server_op(*this)(ec); 54 | }while (is_parent()); 55 | protocolprocesser(m_client_socket); 56 | } 57 | } 58 | 59 | }; 60 | 61 | } 62 | 63 | template 64 | void acceptor_server(boost::asio::io_service & io, const boost::asio::ip::basic_endpoint & endpoint, ProtocolProcesser protocolprocesser) 65 | { 66 | detail::acceptor_server_op(io, endpoint, protocolprocesser); 67 | } 68 | 69 | } 70 | 71 | 72 | #endif // AV_ACCEPTOR_SERVER_H 73 | -------------------------------------------------------------------------------- /avboost/include/boost/async_dir_walk.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | namespace boost{ 11 | namespace detail{ 12 | 13 | class DirWalkDumyHandler{ 14 | public: 15 | void operator()(boost::system::error_code ec){} 16 | }; 17 | 18 | } // namespace detail 19 | 20 | typedef function async_dir_walk_continue_handler; 21 | 22 | template 23 | void async_dir_walk(boost::asio::io_service & io_service, boost::filesystem::path path, DirWalkHandler dir_walk_handler, CompleteHandler complete_handler) 24 | { 25 | async_foreach(io_service, boost::filesystem::directory_iterator(path), boost::filesystem::directory_iterator(), dir_walk_handler, complete_handler); 26 | } 27 | 28 | template 29 | void async_dir_walk(boost::asio::io_service & io_service, boost::filesystem::path path, DirWalkHandler dir_walk_handler) 30 | { 31 | async_dir_walk(io_service, path, dir_walk_handler, detail::DirWalkDumyHandler()); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /avboost/include/boost/async_foreach.hpp: -------------------------------------------------------------------------------- 1 |  2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace boost{ 11 | namespace detail{ 12 | 13 | template 14 | class async_foreach_op : asio::coroutine 15 | { 16 | asio::io_service & m_io_service; 17 | InputIterator m_first, m_last, m_current; 18 | Pred _pred; 19 | Handler m_handler; 20 | public: 21 | typedef void result_type; 22 | 23 | async_foreach_op(asio::io_service & io_service, InputIterator first, InputIterator last, Pred pred, Handler handler) 24 | : m_io_service(io_service), m_first(first), m_last(last), _pred(pred), m_handler(handler) 25 | { 26 | avloop_idle_post(m_io_service, asio::detail::bind_handler(*this, boost::system::error_code())); 27 | } 28 | 29 | void operator()(system::error_code ec) 30 | { 31 | // 好了,每次回调检查一个文件,这样才好,对吧. 32 | BOOST_ASIO_CORO_REENTER(this) 33 | { 34 | for( m_current = m_first; m_current != m_last ; ++m_current) 35 | { 36 | // 好,处理 dir_it_cur dir_it_; 37 | BOOST_ASIO_CORO_YIELD 38 | _pred(*m_current, m_io_service.wrap(bind(*this, _1))); 39 | 40 | BOOST_ASIO_CORO_YIELD 41 | avloop_idle_post(m_io_service, asio::detail::bind_handler(*this, ec)); 42 | } 43 | 44 | avloop_idle_post(m_io_service, asio::detail::bind_handler(m_handler, ec)); 45 | } 46 | } 47 | 48 | }; 49 | 50 | template 51 | async_foreach_op 52 | make_async_foreach_op(asio::io_service &io_service, InputIterator first, InputIterator last , Pred pred, Handler handler) 53 | { 54 | return async_foreach_op(io_service, first, last, pred, handler); 55 | } 56 | 57 | } // namespace detail 58 | 59 | template 60 | void async_foreach(asio::io_service &io_service, InputIterator first, InputIterator last , Pred pred, Handler handler) 61 | { 62 | detail::make_async_foreach_op(io_service, first, last, pred, handler); 63 | } 64 | 65 | } // namespace boost 66 | -------------------------------------------------------------------------------- /avboost/include/boost/avproxy.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "avproxy/avproxy.hpp" 4 | -------------------------------------------------------------------------------- /avboost/include/boost/avproxy/auto_proxychain.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "detail/proxy_chain.hpp" 7 | #include "proxies.hpp" 8 | 9 | namespace avproxy{ 10 | 11 | namespace detail{ 12 | 13 | static boost::asio::ip::tcp::resolver::query queryfromstr(std::string str) 14 | { 15 | std::size_t pos; 16 | pos = str.find("http://"); 17 | if ( pos != std::string::npos) 18 | { 19 | // 应该是 http_proxy=http://host[:port] 20 | str = str.substr(pos+7); 21 | pos = str.find(':'); 22 | if ( pos != std::string::npos) 23 | { 24 | // 应该是 http_proxy=http://host 25 | // 默认 80 端口即可. 26 | return boost::asio::ip::tcp::resolver::query(str, "80"); 27 | } 28 | return queryfromstr(str); 29 | } 30 | 31 | pos = str.find(':'); 32 | std::string host = str.substr(0, pos); 33 | std::string port = str.substr(pos+1); 34 | return boost::asio::ip::tcp::resolver::query(host, port); 35 | } 36 | 37 | } 38 | // automanticaly build proxychain 39 | // accourding to env variables http_proxy and socks5_proxy 40 | // to use socks5 proxy, set socks5_proxy="host:port" 41 | template 42 | proxy_chain autoproxychain(boost::asio::io_context& io, Socket & socket,const typename Socket::protocol_type::resolver::query & _query) 43 | { 44 | proxy_chain _proxychain(io); 45 | if (std::getenv("socks5_proxy")) 46 | { // add socks5_proxy 47 | _proxychain.add(proxy::tcp(socket, detail::queryfromstr(std::getenv("socks5_proxy")))); 48 | _proxychain.add(proxy::socks5(socket, _query)); 49 | }else if (std::getenv("http_proxy")){ 50 | _proxychain.add(proxy::tcp(socket, detail::queryfromstr(std::getenv("http_proxy")))); 51 | _proxychain.add(proxy::http(socket, _query)); 52 | }else{ 53 | _proxychain.add(proxy::tcp(socket, _query)); 54 | } 55 | return _proxychain; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /avboost/include/boost/avproxy/avproxy.hpp: -------------------------------------------------------------------------------- 1 |  2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef BOOST_ENABLE_SSL 9 | #include 10 | #endif 11 | 12 | 13 | #include "detail/connect_condition.hpp" 14 | #include "detail/proxy_chain.hpp" 15 | 16 | #include "proxy_connect.hpp" 17 | #include "proxies.hpp" 18 | #include "auto_proxychain.hpp" 19 | -------------------------------------------------------------------------------- /avboost/include/boost/avproxy/detail/connect_condition.hpp: -------------------------------------------------------------------------------- 1 |  2 | #pragma once 3 | 4 | 5 | namespace avproxy { 6 | 7 | namespace detail{ 8 | 9 | struct avproxy_default_connect_condition{ 10 | template 11 | Iterator operator()( 12 | const boost::system::error_code& ec, 13 | Iterator next) 14 | { 15 | return next; 16 | } 17 | }; 18 | 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /avboost/include/boost/avproxy/detail/error.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace avproxy{ 8 | namespace error{ 9 | 10 | enum proxy_errors{ 11 | proxy_connection_refused = 5000, 12 | proxy_refused = 5000, 13 | proxy_not_authorized, 14 | proxy_unknow_error, 15 | }; 16 | 17 | namespace detail{ 18 | class avproxy_category; 19 | } 20 | 21 | template 22 | const boost::system::error_category& error_category_single() 23 | { 24 | static error_category error_category_instance; 25 | return reinterpret_cast(error_category_instance); 26 | } 27 | 28 | inline const boost::system::error_category& get_avproxy_category() 29 | { 30 | return error_category_single(); 31 | } 32 | 33 | inline boost::system::error_code make_error_code(proxy_errors e) 34 | { 35 | return boost::system::error_code( 36 | static_cast(e), get_avproxy_category()); 37 | } 38 | 39 | 40 | namespace detail { 41 | 42 | class avproxy_category : public boost::system::error_category { 43 | public: 44 | const char* name() const BOOST_NOEXCEPT { 45 | return "avproxy.proxy"; 46 | } 47 | 48 | std::string message ( int value ) const { 49 | if ( value == proxy_connection_refused ) 50 | return "remote proxy refused the connection"; 51 | 52 | if ( value == proxy_not_authorized ) 53 | return "authorizing to proxy failed"; 54 | 55 | return "avproxy.proxy error"; 56 | } 57 | }; 58 | 59 | } // namespace detail 60 | 61 | } // namespace error 62 | } // namespace avproxy 63 | 64 | namespace boost { 65 | namespace system { 66 | 67 | template<> struct is_error_code_enum 68 | { 69 | static const bool value = true; 70 | }; 71 | 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /avboost/include/boost/avproxy/detail/proxy_chain.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | namespace avproxy { 8 | 9 | class proxy_chain; 10 | 11 | namespace detail { 12 | 13 | // 为proxy_chian提供便利的添加语法的辅助类. 14 | struct proxychain_adder{ 15 | proxychain_adder( proxy_chain & _chain) 16 | :chain(&_chain) 17 | { 18 | } 19 | 20 | template 21 | proxychain_adder operator()(const Proxy & proxy ); 22 | 23 | operator proxy_chain& (){ 24 | return *chain; 25 | } 26 | operator proxy_chain (); 27 | 28 | private: 29 | proxy_chain * chain; 30 | }; 31 | 32 | class proxy_base; 33 | } 34 | 35 | class proxy_chain { 36 | public: 37 | proxy_chain(boost::asio::io_context& _io):io_(_io){} 38 | 39 | detail::proxy_base * back(){ 40 | return m_chain.back().get(); 41 | } 42 | 43 | // 克隆一个自己,然后弹出第一个元素. 44 | // 也就是克隆一个少一个元素的 proxy_chain 45 | proxy_chain clone_poped(){ 46 | proxy_chain p(*this); 47 | p.m_chain.pop_back(); 48 | return p; 49 | } 50 | 51 | detail::proxychain_adder add(){ 52 | return detail::proxychain_adder(*this); 53 | } 54 | 55 | template 56 | proxy_chain add(const Proxy & proxy) 57 | { 58 | // 拷贝构造一个新的. 59 | detail::proxy_base * newproxy = new Proxy(proxy); 60 | add_proxy_base(newproxy); 61 | return *this; 62 | } 63 | 64 | boost::asio::io_service& get_io_service(){ 65 | return io_; 66 | } 67 | protected: 68 | void add_proxy_base(detail::proxy_base * proxy){ 69 | m_chain.insert(m_chain.begin(), boost::shared_ptr(proxy) ); 70 | } 71 | private: 72 | boost::asio::io_service& io_; 73 | std::vector > m_chain; 74 | 75 | friend struct detail::proxychain_adder; 76 | }; 77 | 78 | namespace detail{ 79 | class proxy_base { 80 | public: 81 | typedef boost::function< void (const boost::system::error_code&) > handler_type; 82 | public: 83 | template 84 | void resolve(Handler handler, proxy_chain subchain){ 85 | _resolve(handler_type(handler), subchain); 86 | } 87 | 88 | template 89 | void handshake(Handler handler,proxy_chain subchain){ 90 | _handshake(handler_type(handler), subchain); 91 | } 92 | 93 | virtual ~proxy_base(){} 94 | 95 | private: 96 | virtual void _resolve(handler_type, proxy_chain subchain) = 0; 97 | virtual void _handshake(handler_type, proxy_chain subchain) = 0; 98 | }; 99 | } 100 | 101 | template 102 | detail::proxychain_adder detail::proxychain_adder::operator()( const Proxy & proxy ) 103 | { 104 | // 拷贝构造一个新的. 105 | proxy_base * newproxy = new Proxy(proxy); 106 | chain->add_proxy_base(newproxy); 107 | return *this; 108 | } 109 | 110 | inline 111 | detail::proxychain_adder::operator proxy_chain() 112 | { 113 | return *chain; 114 | } 115 | 116 | } // namespace avproxy 117 | -------------------------------------------------------------------------------- /avboost/include/boost/avproxy/detail/proxy_error_mapper.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | namespace avproxy{ 6 | 7 | namespace proxy{ 8 | 9 | namespace detail{ 10 | template 11 | void proxy_error_mapper(const boost::system::error_code & _ec, Handler handler) 12 | { 13 | boost::system::error_code ec = _ec; 14 | if (ec == boost::asio::error::connection_refused) 15 | { 16 | ec = avproxy::error::make_error_code(avproxy::error::proxy_connection_refused); 17 | } 18 | handler(ec); 19 | } 20 | } 21 | 22 | }// proxy 23 | 24 | }// avproxy 25 | -------------------------------------------------------------------------------- /avboost/include/boost/avproxy/detail/proxy_http.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "./error.hpp" 10 | #include "proxy_chain.hpp" 11 | #include "../proxy_connect.hpp" 12 | #include "proxy_error_mapper.hpp" 13 | 14 | namespace avproxy{ 15 | 16 | namespace proxy{ 17 | 18 | namespace detail{ 19 | 20 | template 21 | class async_safe_read_until_op : boost::asio::coroutine { 22 | private: 23 | AsyncReadStream &m_stream; 24 | boost::asio::basic_streambuf & m_buf; 25 | const std::string m_delim; 26 | ReadHandler m_handler; 27 | public: 28 | typedef void result_type; 29 | 30 | async_safe_read_until_op(AsyncReadStream& s, 31 | boost::asio::basic_streambuf& b, const std::string& delim, 32 | ReadHandler handler) 33 | :m_buf(b), m_stream(s), m_delim(delim), m_handler(handler) 34 | { 35 | boost::asio::post(m_stream.get_executor(), boost::bind(*this, boost::system::error_code(), 0)); 36 | } 37 | void operator()(const boost::system::error_code & ec, std::size_t length) 38 | { 39 | BOOST_ASIO_CORO_REENTER(this) 40 | { 41 | // 一次读取一个字节. 42 | do{ 43 | BOOST_ASIO_CORO_YIELD boost::asio::async_read(m_stream, m_buf.prepare(1), *this); 44 | if ( ec) break; 45 | m_buf.commit(length); 46 | }while(!check_delim()); 47 | boost::asio::post(m_stream.get_executor(), 48 | boost::asio::detail::bind_handler((m_handler), ec, m_buf.size()) 49 | ); 50 | } 51 | } 52 | private: 53 | bool check_delim() 54 | { 55 | // 检查 m_buf 里是不是有 delim 56 | std::string response(boost::asio::buffer_cast(m_buf.data()), m_buf.size()); 57 | return response.find(m_delim) != std::string::npos; 58 | } 59 | }; 60 | 61 | /** 62 | * async_safe_read_until 安全的读取到 delim 为止,绝对不多读一个字节。 63 | * 内部实现是每次读取一个字节,所以为了效率考虑请不要使用这个接口哦. 64 | */ 65 | template 66 | void async_safe_read_until(AsyncReadStream& s, 67 | boost::asio::basic_streambuf& b, const std::string& delim, ReadHandler handler) 68 | { 69 | // If you get an error on the following line it means that your handler does 70 | // not meet the documented type requirements for a ReadHandler. 71 | 72 | //BOOST_ASIO_READ_HANDLER_CHECK(ReadHandler, handler) type_check; 73 | 74 | async_safe_read_until_op( 75 | s, b, delim, handler 76 | ); 77 | } 78 | 79 | } 80 | 81 | // 使用 http代理 发起连接. 82 | // TODO, 添加认证支持. 83 | class http : public avproxy::detail::proxy_base , boost::asio::coroutine{ 84 | public: 85 | typedef boost::asio::ip::tcp::resolver::query query; 86 | typedef boost::asio::ip::tcp::socket socket; 87 | typedef void result_type; 88 | 89 | // _query 目的地址 90 | http(socket &_socket,const query & _query) 91 | :socket_(_socket), query_(_query) 92 | { 93 | 94 | } 95 | private: 96 | void _resolve(handler_type handler, proxy_chain subchain){ 97 | // 执行下层 proxy 的链接,通常是 tcp 98 | // TODO: 将这里的错误从 connection-refuse 改成  proxy_connectio_refuse 99 | handler_type _handler = boost::bind(detail::proxy_error_mapper, _1, handler); 100 | 101 | avproxy::async_proxy_connect(subchain, _handler); 102 | } 103 | 104 | // 执行 HTTP 的 handshake, 要异步哦. 105 | void _handshake(handler_type handler, proxy_chain subchain ){ 106 | 107 | boost::asio::post(socket_.get_executor(), boost::asio::detail::bind_handler(*this, boost::system::error_code(), 0, handler)); 108 | } 109 | public: 110 | void operator()(boost::system::error_code ec, std::size_t length, handler_type handler) 111 | { 112 | const char * buffer = NULL; 113 | if (m_buffer) 114 | buffer = boost::asio::buffer_cast(m_buffer->data()); 115 | BOOST_ASIO_CORO_REENTER(this) 116 | { 117 | do{ 118 | // 写入 CONNECT XXX:XXX 119 | // TODO, 支持认证. 120 | BOOST_ASIO_CORO_YIELD boost::asio::async_write(socket_, boost::asio::buffer( 121 | std::string("CONNECT ") + query_.host_name() + ":" + query_.service_name() + "HTTP/1.1\r\n\r\n" 122 | ), boost::bind(*this, _1, _2, handler)); 123 | if (ec) break; 124 | m_buffer.reset(new boost::asio::streambuf); 125 | detail::async_safe_read_until(socket_, *m_buffer, "\r\n\r\n" , boost::bind(*this, _1, _2, handler)); 126 | if (ec) break; 127 | // 解析是不是 HTTP 200 OK 128 | if (check_status()==200) 129 | { 130 | ec = boost::system::error_code(); 131 | }else { 132 | ec = error::make_error_code(error::proxy_unknow_error); 133 | } 134 | }while (false); 135 | boost::asio::post(socket_.get_executor(), boost::asio::detail::bind_handler(handler, ec)); 136 | } 137 | } 138 | 139 | void _async_write_some(){ 140 | 141 | } 142 | 143 | private: 144 | unsigned check_status () 145 | { 146 | std::string ver; 147 | unsigned status; 148 | 149 | std::istream response(m_buffer.get()); 150 | response >> ver >> status; 151 | return status; 152 | } 153 | 154 | private: 155 | boost::shared_ptr m_buffer; 156 | socket& socket_; 157 | const query query_; 158 | }; 159 | 160 | 161 | } // namespace proxy 162 | } // namespace avproxy -------------------------------------------------------------------------------- /avboost/include/boost/avproxy/detail/proxy_socks5.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "./error.hpp" 10 | #include "proxy_chain.hpp" 11 | #include "../proxy_connect.hpp" 12 | 13 | #include "proxy_error_mapper.hpp" 14 | 15 | namespace avproxy{ 16 | 17 | namespace proxy{ 18 | 19 | // 使用 socks5代理 发起连接. 20 | // TODO, 添加认证支持. 21 | class socks5 : public avproxy::detail::proxy_base , boost::asio::coroutine{ 22 | public: 23 | typedef boost::asio::ip::tcp::resolver::query query; 24 | typedef boost::asio::ip::tcp::socket socket; 25 | typedef void result_type; 26 | 27 | socks5(socket &_socket,const query & _query) 28 | :socket_(_socket), query_(_query) 29 | { 30 | 31 | } 32 | private: 33 | void _resolve(handler_type handler, proxy_chain subchain){ 34 | // 执行下层 proxy 的链接,通常是 tcp 35 | // TODO: 将这里的错误从 connection-refuse 改成  proxy_connectio_refuse 36 | handler_type _handler = boost::bind(detail::proxy_error_mapper, _1, handler); 37 | 38 | avproxy::async_proxy_connect(subchain, _handler); 39 | } 40 | 41 | void _handshake(handler_type handler, proxy_chain subchain ){ 42 | // 执行 socks5 的 handshake, 要异步哦. 43 | boost::asio::post(socket_.get_executor(), boost::asio::detail::bind_handler(*this, boost::system::error_code(), 0, handler)); 44 | } 45 | public: 46 | void operator()(boost::system::error_code ec, std::size_t length, handler_type handler) 47 | { 48 | static const char socks5_command[3] = {5, 1, 0}; 49 | const char * buffer = NULL; 50 | if (m_buffer) 51 | buffer = boost::asio::buffer_cast(m_buffer->data()); 52 | BOOST_ASIO_CORO_REENTER(this) 53 | { 54 | do{ 55 | // 写入 0x05, 0x00 56 | // TODO, 支持认证. 57 | BOOST_ASIO_CORO_YIELD boost::asio::async_write(socket_, boost::asio::buffer(socks5_command), boost::bind(*this, _1, _2, handler)); 58 | if (ec) break; 59 | m_buffer.reset(new boost::asio::streambuf); 60 | BOOST_ASIO_CORO_YIELD boost::asio::async_read(socket_, m_buffer->prepare(2), boost::bind(*this, _1, _2, handler)); 61 | if (ec) break; 62 | // 解析是不是 0x05, 0x00 63 | m_buffer->commit(length); 64 | if (!(buffer[0] == 5 && buffer[1] == 0)) 65 | { 66 | ec = error::make_error_code(error::proxy_not_authorized); 67 | break; 68 | } 69 | // 执行 connect 命令. 70 | BOOST_ASIO_CORO_YIELD boost::asio::async_write(socket_, boost::asio::buffer(buildsocks5connectcmd()), boost::bind(*this, _1, _2, handler)); 71 | if (ec) break; 72 | m_buffer.reset(new boost::asio::streambuf); 73 | // 读取 socks5 server 返回值. 74 | BOOST_ASIO_CORO_YIELD boost::asio::async_read(socket_, m_buffer->prepare(4), boost::bind(*this, _1, _2, handler)); 75 | if (ec) break; 76 | m_buffer->commit(length); 77 | 78 | // 解析返回值. 79 | if (!(length==4 && buffer[0] == 5 && buffer[1] == 0 && buffer[2] == 0 )) 80 | { 81 | ec = error::make_error_code(error::proxy_not_authorized); 82 | break; 83 | } 84 | 85 | // ATYPE==ipv4 86 | if (boost::asio::buffer_cast(m_buffer->data())[3] == 1){ 87 | BOOST_ASIO_CORO_YIELD boost::asio::async_read(socket_, m_buffer->prepare(6), boost::bind(*this, _1, _2, handler)); 88 | m_buffer->commit(length); 89 | }else if (boost::asio::buffer_cast(m_buffer->data())[3]==4){ 90 | BOOST_ASIO_CORO_YIELD boost::asio::async_read(socket_, m_buffer->prepare(18), boost::bind(*this, _1, _2, handler)); 91 | m_buffer->commit(length); 92 | }else if (boost::asio::buffer_cast(m_buffer->data())[3]==3){ 93 | ec = error::make_error_code(error::proxy_unknow_error); 94 | }else{ 95 | // 出错. 96 | ec = error::make_error_code(error::proxy_unknow_error); 97 | } 98 | if (ec) break; 99 | }while (false); 100 | boost::asio::post(socket_.get_executor(), boost::asio::detail::bind_handler(handler, ec)); 101 | } 102 | } 103 | 104 | void _async_write_some(){ 105 | 106 | } 107 | 108 | private: 109 | // 0x05 0x01 0x00 0x03 [length]ipaddr [port] 110 | std::vector buildsocks5connectcmd() 111 | { 112 | std::vector cmd(4 + 1 + query_.host_name().length() + 2 ); 113 | unsigned short port = boost::lexical_cast(query_.service_name()); 114 | cmd[0] = 5; 115 | cmd[1] = 1; 116 | cmd[2] = 0; 117 | cmd[3] = 3; 118 | cmd[4] = query_.host_name().length(); 119 | std::memcpy(&cmd[5], query_.host_name().c_str(), query_.host_name().length()); 120 | cmd[5+query_.host_name().length()] = port >> 8; 121 | cmd[5+query_.host_name().length() + 1 ] = port & 0xFF; 122 | return cmd;//boost::asio::buffer(cmd, cmd.size()); 123 | } 124 | 125 | private: 126 | boost::shared_ptr m_buffer; 127 | socket& socket_; 128 | const query query_; 129 | }; 130 | 131 | 132 | } // namespace proxy 133 | } // namespace avproxy 134 | 135 | -------------------------------------------------------------------------------- /avboost/include/boost/avproxy/detail/proxy_ssl.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include "proxy_chain.hpp" 7 | #include "../proxy_connect.hpp" 8 | 9 | namespace avproxy{ 10 | namespace proxy{ 11 | 12 | // SSL 连接过程. 支持透过代理发起 SSL 连接哦! 13 | // TODO 14 | class proxy_ssl : public avproxy::detail::proxy_base{ 15 | public: 16 | typedef boost::asio::ip::tcp tcp; 17 | typedef tcp::resolver::query query; 18 | typedef tcp::socket socket; 19 | 20 | proxy_ssl(boost::asio::ssl::stream &stream, query _query) 21 | { 22 | 23 | } 24 | 25 | private: 26 | void _resolve(handler_type handler, proxy_chain subchain){ 27 | // 递归调用 avconnect 传递到下一层. 28 | avproxy::async_proxy_connect(subchain, handler); 29 | } 30 | 31 | void _handshake(handler_type handler, proxy_chain subchain ){ 32 | // 调用 ssl 的 async_handshake 33 | // TODO 34 | } 35 | 36 | }; 37 | 38 | } // namespace proxy 39 | } // namespace avproxy -------------------------------------------------------------------------------- /avboost/include/boost/avproxy/detail/proxy_tcp.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "proxy_chain.hpp" 4 | #include "../proxy_connect.hpp" 5 | 6 | namespace avproxy{ 7 | namespace proxy{ 8 | // 使用 TCP 发起连接. 也就是不使用代理啦. 9 | class tcp : public avproxy::detail::proxy_base { 10 | public: 11 | typedef boost::asio::ip::tcp::resolver::query query; 12 | typedef boost::asio::ip::tcp::socket socket; 13 | 14 | tcp(socket &_socket,const query & _query) 15 | :socket_(_socket), query_(_query) 16 | { 17 | } 18 | private: 19 | void _resolve(handler_type handler, proxy_chain subchain){ 20 | //handler(boost::system::error_code()); 21 | boost::asio::post(socket_.get_executor(), boost::asio::detail::bind_handler(handler, boost::system::error_code())); 22 | } 23 | 24 | void _handshake(handler_type handler, proxy_chain subchain ){ 25 | avproxy::async_connect(socket_, query_, handler); 26 | } 27 | 28 | socket& socket_; 29 | const query query_; 30 | }; 31 | 32 | 33 | } // namespace proxy 34 | } // namespace avproxy -------------------------------------------------------------------------------- /avboost/include/boost/avproxy/proxies.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "detail/proxy_chain.hpp" 4 | #include "detail/proxy_tcp.hpp" 5 | #include "detail/proxy_socks5.hpp" 6 | #include "detail/proxy_http.hpp" 7 | 8 | #ifdef BOOST_ENABLE_SSL 9 | #include "detail/proxy_ssl.hpp" 10 | #endif 11 | -------------------------------------------------------------------------------- /avboost/include/boost/avproxy/proxy_connect.hpp: -------------------------------------------------------------------------------- 1 |  2 | #pragma once 3 | 4 | #ifdef __llvm__ 5 | #pragma GCC diagnostic ignored "-Wdangling-else" 6 | #endif 7 | 8 | #include 9 | 10 | #include "detail/proxy_chain.hpp" 11 | 12 | namespace avproxy { 13 | 14 | // convient helper class that made for direct TCP connection without proxy 15 | // usage: 16 | // avproxy::async_connect( socket , ip::tcp::resolve::query( "host" , "port" ) , handler ); 17 | // the hander should be this signature 18 | // void handle_connect( 19 | // const boost::system::error_code & ec 20 | // ) 21 | class async_connect : boost::asio::coroutine 22 | { 23 | public: 24 | typedef void result_type; // for boost::bind 25 | public: 26 | template 27 | async_connect(Socket & socket,const typename Socket::protocol_type::resolver::query & _query, BOOST_ASIO_MOVE_ARG(Handler) handler, connect_condition _connect_condition) 28 | { 29 | //BOOST_ASIO_CONNECT_HANDLER_CHECK(Handler, handler) type_check; 30 | _async_connect(socket, _query, boost::function(handler), _connect_condition); 31 | } 32 | 33 | template 34 | async_connect(Socket & socket,const typename Socket::protocol_type::resolver::query & _query, BOOST_ASIO_MOVE_ARG(Handler) handler) 35 | { 36 | //BOOST_ASIO_CONNECT_HANDLER_CHECK(Handler, handler) type_check; 37 | _async_connect(socket, _query, boost::function(handler), detail::avproxy_default_connect_condition()); 38 | } 39 | 40 | template 41 | void operator()(const boost::system::error_code & ec, typename Socket::protocol_type::resolver::iterator begin, Socket & socket, boost::shared_ptr resolver, Handler handler, connect_condition _connect_condition) 42 | { 43 | //BOOST_ASIO_CONNECT_HANDLER_CHECK(Handler, handler) type_check; 44 | 45 | BOOST_ASIO_CORO_REENTER(this) 46 | { 47 | BOOST_ASIO_CORO_YIELD boost::asio::async_connect(socket,begin, _connect_condition, boost::bind(*this, _1, _2, boost::ref(socket), resolver, handler, _connect_condition)); 48 | boost::asio::post(socket.get_executor(), boost::asio::detail::bind_handler(handler,ec)); 49 | } 50 | } 51 | private: 52 | template 53 | void _async_connect(Socket & socket,const typename Socket::protocol_type::resolver::query & _query, BOOST_ASIO_MOVE_ARG(Handler) handler, connect_condition _connect_condition) 54 | { 55 | //BOOST_ASIO_CONNECT_HANDLER_CHECK(Handler, handler) type_check; 56 | 57 | typedef typename Socket::protocol_type::resolver resolver_type; 58 | 59 | boost::shared_ptr 60 | resolver(new resolver_type(socket.get_executor())); 61 | resolver->async_resolve(_query, boost::bind(*this, _1, _2, boost::ref(socket), resolver, handler, _connect_condition)); 62 | } 63 | }; 64 | 65 | // 带 proxy 执行连接. 66 | template 67 | class async_proxy_connect_op : boost::asio::coroutine 68 | { 69 | public: 70 | typedef void result_type; // for boost::bind_handler 71 | public: 72 | async_proxy_connect_op(const proxy_chain &proxy_chain, Handler &handler) 73 | : proxy_chain_(proxy_chain) 74 | , m_handler(handler) 75 | { 76 | } 77 | 78 | void operator()(boost::system::error_code ec = {}) 79 | { 80 | BOOST_ASIO_CORO_REENTER(this) 81 | { 82 | // resolve 83 | BOOST_ASIO_CORO_YIELD proxy_chain_.back()->resolve(*this, proxy_chain_.clone_poped()); 84 | if(! ec) 85 | BOOST_ASIO_CORO_YIELD proxy_chain_.back()->handshake(*this, proxy_chain_.clone_poped()); 86 | m_handler(ec); 87 | } 88 | } 89 | private: 90 | proxy_chain proxy_chain_; 91 | Handler m_handler; 92 | }; 93 | 94 | struct initiate_do_async_proxy_connect 95 | { 96 | template 97 | void operator()(Handler&& handler, const proxy_chain *proxy_chain) const 98 | { 99 | async_proxy_connect_op(*proxy_chain, handler)(); 100 | } 101 | 102 | }; 103 | 104 | template 105 | auto async_proxy_connect(const proxy_chain &proxy_chain, BOOST_ASIO_MOVE_ARG(RealHandler) handler) 106 | { 107 | using namespace boost::asio; 108 | 109 | BOOST_ASIO_CONNECT_HANDLER_CHECK(RealHandler, handler) type_check; 110 | 111 | return boost::asio::async_initiate( 112 | initiate_do_async_proxy_connect{}, handler, &proxy_chain); 113 | 114 | } 115 | 116 | } 117 | -------------------------------------------------------------------------------- /avboost/include/boost/base64.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | namespace boost { 15 | 16 | typedef archive::iterators::transform_width< 17 | archive::iterators::binary_from_base64 >, 8, 6, char> 18 | base64decodeIterator; 19 | 20 | typedef archive::iterators::base64_from_binary< 21 | archive::iterators::transform_width > 22 | base64encodeIterator; 23 | 24 | // BASE64 解码. 25 | inline std::string base64_decode(std::string str) 26 | { 27 | static int shrik_map[] = {0, 2, 1}; 28 | 29 | // 移除尾部的 == 后面的 \r\n\r\n 30 | while ( boost::is_any_of("\r\n.")(* str.rbegin())) 31 | str.erase(str.length()-1); 32 | // 统计结尾的 = 数目 33 | std::size_t num = 0; 34 | if (str.find_last_of("=")!=std::string::npos) 35 | num = str.find_last_of("=") - str.find_first_of("=") + 1; 36 | 37 | BOOST_ASSERT(num < 3); 38 | 39 | std::size_t num_to_shrik = shrik_map[num]; 40 | 41 | // convert base64 characters to binary values 42 | std::string result(base64decodeIterator(str.c_str()), base64decodeIterator(str.c_str() + str.length())); 43 | 44 | result.erase(result.length() -1 - num_to_shrik, num_to_shrik); 45 | return result; 46 | } 47 | 48 | // BASE64 编码. 49 | inline std::string base64_encode(std::string src) 50 | { 51 | std::vector result(src.length()/3*4+6); 52 | unsigned one_third_len = src.length()/3; 53 | 54 | unsigned len_rounded_down = one_third_len*3; 55 | unsigned j = len_rounded_down + one_third_len; 56 | 57 | std::string base64str; 58 | 59 | // 3 的整数倍可以编码. 60 | std::copy(base64encodeIterator(src.begin()), base64encodeIterator(src.begin() + len_rounded_down), result.begin()); 61 | 62 | base64str = result.data(); 63 | 64 | // 结尾 0 填充以及使用 = 补上 65 | if (len_rounded_down != src.length()) 66 | { 67 | std::string tail; 68 | tail.resize(4, 0); 69 | unsigned i=0; 70 | for(; i < src.length() - len_rounded_down; ++i) 71 | { 72 | tail[i] = src[len_rounded_down+i]; 73 | } 74 | 75 | std::string tailbase; 76 | tailbase.resize(5); 77 | 78 | std::copy(base64encodeIterator(tail.begin()), base64encodeIterator(tail.begin() + 3), tailbase.begin()); 79 | for (int k=0;k<(3-i);k++){ 80 | tailbase[3-k] = '='; 81 | } 82 | 83 | base64str += tailbase.data(); 84 | } 85 | return base64str; 86 | } 87 | 88 | // BASE64 编码. 89 | template 90 | void base64_encode(std::string src, OStreamIterator ostream_iterator) 91 | { 92 | unsigned one_third_len = src.length()/3; 93 | 94 | unsigned len_rounded_down = one_third_len*3; 95 | unsigned j = len_rounded_down + one_third_len; 96 | 97 | std::string base64str; 98 | 99 | typedef boost::archive::iterators::insert_linebreaks base64encode_linebreaks_Iterator; 100 | // 3 的整数倍可以编码. 101 | std::copy(base64encode_linebreaks_Iterator(src.begin()), base64encode_linebreaks_Iterator(src.begin() + len_rounded_down), 102 | ostream_iterator 103 | ); 104 | 105 | // 结尾 0 填充以及使用 = 补上 106 | if (len_rounded_down != src.length()) 107 | { 108 | std::string tail; 109 | tail.resize(4, 0); 110 | unsigned i=0; 111 | for(; i < src.length() - len_rounded_down; ++i) 112 | { 113 | tail[i] = src[len_rounded_down+i]; 114 | } 115 | 116 | std::string tailbase; 117 | tailbase.resize(5); 118 | 119 | std::copy(base64encode_linebreaks_Iterator(tail.begin()), base64encode_linebreaks_Iterator(tail.begin() + 3), tailbase.begin()); 120 | for (int k=0;k<(3-i);k++){ 121 | tailbase[3-k] = '='; 122 | } 123 | 124 | std::string base64str(tailbase.data()); 125 | std::copy(base64str.begin(), base64str.end(), ostream_iterator); 126 | } 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /avboost/include/boost/bin_from_hex.hpp: -------------------------------------------------------------------------------- 1 |  2 | #pragma once 3 | 4 | #include 5 | 6 | namespace boost{ 7 | template 8 | struct bin_from_hex : public boost::iterator_adaptor < 9 | bin_from_hex, 10 | Base, 11 | uint8_t, 12 | boost::single_pass_traversal_tag, 13 | uint8_t 14 | > 15 | { 16 | friend class boost::iterator_core_access; 17 | typedef BOOST_DEDUCED_TYPENAME boost::iterator_adaptor < 18 | bin_from_hex, 19 | Base, 20 | uint8_t, 21 | boost::single_pass_traversal_tag, 22 | uint8_t 23 | > super_t; 24 | 25 | typedef bin_from_hex this_t; 26 | typedef uint8_t CharType; 27 | 28 | typedef typename boost::iterator_value::type base_value_type; 29 | 30 | Base m_base; 31 | 32 | static uint8_t hex_to_int(const char c) 33 | { 34 | switch (c) 35 | { 36 | case '0': case '1': case '2': case '3': case '4': 37 | case '5': case '6': case '7': case '8': case '9': 38 | return c - '0'; 39 | case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': 40 | return c - 'a' + 10; 41 | case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': 42 | return c - 'A' + 10; 43 | } 44 | return '?'; 45 | } 46 | 47 | CharType dereference() const { 48 | return hex_to_int(*m_base); 49 | } 50 | 51 | // standard iterator interface 52 | bool equal(const this_t & rhs) const { 53 | return m_base == rhs.m_base; 54 | } 55 | 56 | void increment(){ 57 | ++m_base; 58 | } 59 | 60 | bin_from_hex(const Base & _base) 61 | : m_base(_base) 62 | { 63 | } 64 | }; 65 | 66 | template 67 | struct hex_from_bin 68 | { 69 | typedef hex_from_bin this_t; 70 | typedef char CharType; 71 | 72 | typedef typename boost::iterator_value::type base_value_type; 73 | 74 | typedef std::input_iterator_tag iterator_category; 75 | typedef char value_type; 76 | 77 | typedef typename Base::difference_type difference_type; 78 | typedef typename Base::reference reference; 79 | typedef typename Base::pointer pointer; 80 | 81 | Base m_base; 82 | 83 | static inline char char_to_hex(unsigned c) 84 | { 85 | static char table[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; 86 | return table[c]; 87 | } 88 | 89 | CharType dereference() const { 90 | return char_to_hex(*m_base); 91 | } 92 | 93 | CharType operator * () 94 | { 95 | return dereference(); 96 | } 97 | 98 | // standard iterator interface 99 | bool equal(const this_t & rhs) const { 100 | return m_base == rhs.m_base; 101 | } 102 | 103 | bool operator == (const this_t & rhs) 104 | { 105 | return equal(rhs); 106 | } 107 | 108 | bool operator != (const this_t & rhs) 109 | { 110 | return ! equal(rhs); 111 | } 112 | 113 | 114 | void increment(){ 115 | ++m_base; 116 | } 117 | 118 | void operator ++ () 119 | { 120 | increment(); 121 | } 122 | 123 | hex_from_bin(Base const & _base) 124 | : m_base(_base) 125 | { 126 | } 127 | }; 128 | 129 | #ifdef _______EXAMPLE_TEST_CODE 130 | 131 | // 就是这样的代码. 就完成转换了, 细细. 132 | std::string bintohexstrubg(std::string md5bin) 133 | { 134 | typedef boost::hex_from_bin< 135 | boost::archive::iterators::transform_width 136 | > hex_from_bin_iterator; 137 | 138 | return std::string(hex_from_bin_iterator(md5bin.begin()), 139 | hex_from_bin_iterator(md5bin.end())); 140 | } 141 | 142 | #endif 143 | 144 | } 145 | -------------------------------------------------------------------------------- /avboost/include/boost/cfunction.hpp: -------------------------------------------------------------------------------- 1 |  2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace boost { 11 | 12 | /* 13 | * cfunction 用于将 boost::function 拆分为一个 C 函数指针和一个 void * user_data 指针. 14 | * 15 | * 只要接受 一个 C 函数指针 + void * user_data 的地方, 就可以利用 cfunction 封装 boost::function, 16 | * 而 boost::function 又可以继续封装 boost::bind, boost::bind 的强大就无需多说了吧. 17 | * 18 | * 例子在是这样的, 相信这个例子一看大家全明白了, 呵呵 19 | * 20 | static void * my_thread_func2(int a, int b, int c, cfunction func2) 21 | { 22 | // 故意睡一下,保证 那个线程的 func2 对象析构,这个拷贝的 func2 也能维持好 C 函数的数据,避免下面的代码崩溃! 23 | sleep(10); 24 | std::cout << "这样就不用管理 func2 啦!自动释放不是?" << std::endl; 25 | std::cout << a << b << c << std::endl; 26 | return NULL; 27 | } 28 | 29 | static void * my_thread_func(int a, int b, int c) 30 | { 31 | cfunction func2; 32 | 33 | // 通过将自己绑定进去,func2 这个对象就不必保持生命期, 回调执行完毕会自动清空数据! 34 | func2 = boost::bind(&my_thread_func2, 3, 2, 3, func2); 35 | 36 | pthread_t new_thread; 37 | 38 | pthread_create(&new_thread, NULL, func2.c_func_ptr(), func2.c_void_ptr()); 39 | 40 | // 让线程进入不可 join 状态,无需等待线程退出 41 | pthread_detach(new_thread); 42 | 43 | std::cout << a << b << c << std::endl; 44 | return NULL; 45 | // 这里 func2 对象析构了,但是估计那个线程函数还没有执行完毕,如果不 bind 进去,到这里析构后,那个线程就会崩溃。 46 | // 但是,因为将 func2 对象绑定进去了,所以那个线程可以继续安然无恙的运行。 47 | } 48 | 49 | int main(int, char*[]) 50 | { 51 | cfunction func; 52 | 53 | func = boost::bind(&my_thread_func, 1, 2, 3); 54 | 55 | pthread_t new_thread; 56 | 57 | pthread_create(&new_thread, NULL, func.c_func_ptr(), func.c_void_ptr()); 58 | // 等待 线程退出,这样这个 func 对象要保证回调期间的生命期 59 | pthread_join(new_thread, NULL); 60 | 61 | // 等待另一个unjoinable 的线程退出 62 | sleep(100); 63 | return 0; 64 | } 65 | 66 | * 67 | */ 68 | template 69 | class cfunction 70 | { 71 | public: 72 | typedef typename boost::function_traits::result_type return_type; 73 | typedef boost::function closure_type; 74 | private: 75 | boost::shared_ptr m_wrapped_func; 76 | public: 77 | cfunction() 78 | : m_wrapped_func(make_shared()) 79 | { 80 | } 81 | 82 | cfunction(const closure_type &bindedfuntor) 83 | : m_wrapped_func(make_shared()) 84 | { 85 | *m_wrapped_func = bindedfuntor; 86 | } 87 | 88 | cfunction& operator = (const closure_type& bindedfuntor) 89 | { 90 | *m_wrapped_func = closure_type(bindedfuntor); 91 | return *this; 92 | } 93 | 94 | void * c_void_ptr() 95 | { 96 | return m_wrapped_func.get(); 97 | } 98 | 99 | CFuncType c_func_ptr() 100 | { 101 | return (CFuncType)wrapperd_callback; 102 | } 103 | 104 | private: // 这里是一套重载, 被 c_func_ptr() 依据 C 接口的类型挑一个出来并实例化. 105 | static return_type wrapperd_callback(void* user_data) 106 | { 107 | closure_type * wrapped_func = reinterpret_cast(user_data); 108 | 109 | return (*wrapped_func)(); 110 | } 111 | 112 | #define ARG(z, n, _) Arg ## n arg ## n 113 | 114 | #define TEXT(z, n, text) text ## n 115 | 116 | #define TTP(z, n, _) \ 117 | template< \ 118 | BOOST_PP_ENUM_ ## z(BOOST_PP_INC(n), TEXT, typename Arg) \ 119 | > \ 120 | static return_type wrapperd_callback(\ 121 | BOOST_PP_ENUM_ ## z(BOOST_PP_INC(n), ARG, nil), void* user_data) \ 122 | {\ 123 | closure_type * wrapped_func = reinterpret_cast(user_data); \ 124 | return (*wrapped_func)(BOOST_PP_ENUM_ ## z(BOOST_PP_INC(n), TEXT, arg) ); \ 125 | } 126 | 127 | BOOST_PP_REPEAT_FROM_TO(0, 9, TTP, nil) 128 | }; 129 | 130 | 131 | } // namespace boost 132 | -------------------------------------------------------------------------------- /avboost/include/boost/hash.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_HPP 10 | #define BOOST_HASH_HPP 11 | 12 | // Checksums 13 | #include 14 | #include 15 | 16 | // Cryptographic Hashes 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | // Infrastructure 25 | #include 26 | #include 27 | #include 28 | 29 | #endif // BOOST_HASH_HPP 30 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/block_cyphers/detail/basic_functions.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_BLOCK_CYPHERS_DETAIL_BASIC_FUNCTIONS_HPP 10 | #define BOOST_HASH_BLOCK_CYPHERS_DETAIL_BASIC_FUNCTIONS_HPP 11 | 12 | #include 13 | #include 14 | 15 | namespace boost { 16 | namespace hashes { 17 | namespace block_cyphers { 18 | namespace detail { 19 | 20 | template 21 | struct basic_functions { 22 | static unsigned const word_bits = word_bits_N; 23 | typedef typename uint_t::exact word_type; 24 | 25 | static word_type SHR(word_type x, unsigned n) { 26 | return x >> n; 27 | } 28 | template 29 | static word_type SHR(word_type x) { 30 | BOOST_STATIC_ASSERT(n < word_bits); 31 | return x >> n; 32 | } 33 | static word_type SHL(word_type x, unsigned n) { 34 | return x << n; 35 | } 36 | template 37 | static word_type SHL(word_type x) { 38 | BOOST_STATIC_ASSERT(n < word_bits); 39 | return x << n; 40 | } 41 | 42 | static word_type ROTR(word_type x, unsigned n) { 43 | return SHR(x, n) | SHL(x, word_bits-n); 44 | } 45 | template 46 | static word_type ROTR(word_type x) { 47 | return SHR(x) | SHL(x); 48 | } 49 | static word_type ROTL(word_type x, unsigned n) { 50 | return SHL(x, n) | SHR(x, word_bits-n); 51 | } 52 | template 53 | static word_type ROTL(word_type x) { 54 | return SHL(x) | SHR(x); 55 | } 56 | }; 57 | 58 | } // namespace detail 59 | } // namespace block_cyphers 60 | } // namespace hashes 61 | } // namespace boost 62 | 63 | #endif // BOOST_HASH_BLOCK_CYPHERS_DETAIL_BASIC_FUNCTIONS_HPP 64 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/block_cyphers/detail/md4_policy.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_BLOCK_CYPHERS_DETAIL_MD4_POLICY_HPP 10 | #define BOOST_HASH_BLOCK_CYPHERS_DETAIL_MD4_POLICY_HPP 11 | 12 | #include 13 | #include 14 | 15 | namespace boost { 16 | namespace hashes { 17 | namespace block_cyphers { 18 | namespace detail { 19 | 20 | struct md4_functions : basic_functions<32> { 21 | static word_type ff(word_type x, word_type y, word_type z) { 22 | return (x & y) | (~x & z); 23 | } 24 | static word_type gg(word_type x, word_type y, word_type z) { 25 | return (x & y) | (x & z) | (y & z); 26 | } 27 | static word_type hh(word_type x, word_type y, word_type z) { 28 | return x ^ y ^ z; 29 | } 30 | }; 31 | 32 | struct md4_policy : md4_functions { 33 | 34 | static unsigned const block_bits = 128; 35 | static unsigned const block_words = block_bits/word_bits; 36 | typedef array block_type; 37 | 38 | static unsigned const key_words = 16; 39 | static unsigned const key_bits = key_words*word_bits; 40 | typedef array key_type; 41 | 42 | static unsigned const rounds = 48; 43 | typedef array key_indexes_type; 44 | 45 | static unsigned key_index(unsigned t) { 46 | static key_indexes_type const key_indexes = {{ 47 | 0, 1, 2, 3, 48 | 4, 5, 6, 7, 49 | 8, 9, 10, 11, 50 | 12, 13, 14, 15, 51 | 52 | 0, 4, 8, 12, 53 | 1, 5, 9, 13, 54 | 2, 6, 10, 14, 55 | 3, 7, 11, 15, 56 | 57 | 0, 8, 4, 12, 58 | 2, 10, 6, 14, 59 | 1, 9, 5, 13, 60 | 3, 11, 7, 15, 61 | }}; 62 | return key_indexes[t]; 63 | } 64 | }; 65 | 66 | } // namespace detail 67 | } // namespace block_cyphers 68 | } // namespace hashes 69 | } // namespace boost 70 | 71 | #endif // BOOST_HASH_BLOCK_CYPHERS_DETAIL_MD4_POLICY_HPP 72 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/block_cyphers/detail/md5_policy.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_BLOCK_CYPHERS_DETAIL_MD5_POLICY_HPP 10 | #define BOOST_HASH_BLOCK_CYPHERS_DETAIL_MD5_POLICY_HPP 11 | 12 | #include 13 | #include 14 | 15 | namespace boost { 16 | namespace hashes { 17 | namespace block_cyphers { 18 | namespace detail { 19 | 20 | struct md5_functions : detail::basic_functions<32> { 21 | static word_type ff(word_type x, word_type y, word_type z) { 22 | return (x & y) | (~x & z); 23 | } 24 | static word_type gg(word_type x, word_type y, word_type z) { 25 | return (x & z) | (y & ~z); 26 | // return F(z, x, y); 27 | } 28 | static word_type hh(word_type x, word_type y, word_type z) { 29 | return x ^ y ^ z; 30 | } 31 | static word_type ii(word_type x, word_type y, word_type z) { 32 | return y ^ (x | ~z); 33 | } 34 | }; 35 | 36 | struct md5_policy : md5_functions { 37 | 38 | static unsigned const block_bits = 128; 39 | static unsigned const block_words = block_bits/word_bits; 40 | typedef array block_type; 41 | 42 | static unsigned const key_words = 16; 43 | static unsigned const key_bits = key_words*word_bits; 44 | typedef array key_type; 45 | 46 | static unsigned const rounds = 64; 47 | typedef array constants_type; 48 | typedef array key_indexes_type; 49 | 50 | static word_type constant(unsigned t) { 51 | static constants_type const constants = {{ 52 | 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 53 | 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, 54 | 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 55 | 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, 56 | 57 | 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, 58 | 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, 59 | 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 60 | 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, 61 | 62 | 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, 63 | 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, 64 | 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, 65 | 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, 66 | 67 | 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 68 | 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, 69 | 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 70 | 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391, 71 | }}; 72 | return constants[t]; 73 | } 74 | 75 | static unsigned key_index(unsigned t) { 76 | static key_indexes_type const key_indexes = {{ 77 | 0, 1, 2, 3, 78 | 4, 5, 6, 7, 79 | 8, 9, 10, 11, 80 | 12, 13, 14, 15, 81 | 82 | 1, 6, 11, 0, 83 | 5, 10, 15, 4, 84 | 9, 14, 3, 8, 85 | 13, 2, 7, 12, 86 | 87 | 5, 8, 11, 14, 88 | 1, 4, 7, 10, 89 | 13, 0, 3, 6, 90 | 9, 12, 15, 2, 91 | 92 | 0, 7, 14, 5, 93 | 12, 3, 10, 1, 94 | 8, 15, 6, 13, 95 | 4, 11, 2, 9, 96 | }}; 97 | return key_indexes[t]; 98 | } 99 | }; 100 | 101 | } // namespace detail 102 | } // namespace block_cyphers 103 | } // namespace hashes 104 | } // namespace boost 105 | 106 | #endif // BOOST_HASH_BLOCK_CYPHERS_DETAIL_MD5_POLICY_HPP 107 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/block_cyphers/detail/shacal1_policy.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_BLOCK_CYPHERS_DETAIL_SHACAL1_POLICY_HPP 10 | #define BOOST_HASH_BLOCK_CYPHERS_DETAIL_SHACAL1_POLICY_HPP 11 | 12 | #include 13 | 14 | namespace boost { 15 | namespace hashes { 16 | namespace block_cyphers { 17 | namespace detail { 18 | 19 | typedef shacal_policy shacal1_policy; 20 | 21 | } // namespace detail 22 | } // namespace block_cyphers 23 | } // namespace hashes 24 | } // namespace boost 25 | 26 | #endif // BOOST_HASH_BLOCK_CYPHERS_DETAIL_SHACAL1_POLICY_HPP 27 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/block_cyphers/detail/shacal_functions.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_BLOCK_CYPHERS_DETAIL_SHACAL_FUNCTIONS_HPP 10 | #define BOOST_HASH_BLOCK_CYPHERS_DETAIL_SHACAL_FUNCTIONS_HPP 11 | 12 | #include 13 | 14 | namespace boost { 15 | namespace hashes { 16 | namespace block_cyphers { 17 | namespace detail { 18 | 19 | // 20 | // Implemented directly from the standard as found at 21 | // http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf 22 | // 23 | 24 | // Specifically, subsection 4.1 25 | 26 | template 27 | struct basic_shacal_functions : basic_functions { 28 | typedef typename basic_functions::word_type word_type; 29 | 30 | static word_type Ch(word_type x, word_type y, word_type z) { 31 | return (x & y) ^ (~x & z); 32 | } 33 | static word_type Maj(word_type x, word_type y, word_type z) { 34 | return (x & y) ^ (x & z) ^ (y & z); 35 | } 36 | }; 37 | 38 | struct shacal_functions : public basic_shacal_functions<32> { 39 | static word_type Parity(word_type x, word_type y, word_type z) { 40 | return x ^ y ^ z; 41 | } 42 | static word_type f(unsigned t, word_type x, word_type y, word_type z) { 43 | if (t < 40) { 44 | if (t < 20) return Ch(x, y, z); 45 | } else { 46 | if (t < 60) return Maj(x, y, z); 47 | } 48 | return Parity(x, y, z); 49 | } 50 | }; 51 | 52 | typedef shacal_functions shacal0_functions; 53 | typedef shacal_functions shacal1_functions; 54 | 55 | template 56 | struct shacal2_functions; 57 | template <> 58 | struct shacal2_functions<32> : public basic_shacal_functions<32> { 59 | static word_type Sigma_0(word_type x) { 60 | return ROTR< 2>(x) ^ ROTR<13>(x) ^ ROTR<22>(x); 61 | } 62 | static word_type Sigma_1(word_type x) { 63 | return ROTR< 6>(x) ^ ROTR<11>(x) ^ ROTR<25>(x); 64 | } 65 | 66 | static word_type sigma_0(word_type x) { 67 | return ROTR< 7>(x) ^ ROTR<18>(x) ^ SHR< 3>(x); 68 | } 69 | static word_type sigma_1(word_type x) { 70 | return ROTR<17>(x) ^ ROTR<19>(x) ^ SHR<10>(x); 71 | } 72 | }; 73 | template <> 74 | struct shacal2_functions<64> : public basic_shacal_functions<64> { 75 | static word_type Sigma_0(word_type x) { 76 | return ROTR<28>(x) ^ ROTR<34>(x) ^ ROTR<39>(x); 77 | } 78 | static word_type Sigma_1(word_type x) { 79 | return ROTR<14>(x) ^ ROTR<18>(x) ^ ROTR<41>(x); 80 | } 81 | 82 | static word_type sigma_0(word_type x) { 83 | return ROTR< 1>(x) ^ ROTR< 8>(x) ^ SHR< 7>(x); 84 | } 85 | static word_type sigma_1(word_type x) { 86 | return ROTR<19>(x) ^ ROTR<61>(x) ^ SHR< 6>(x); 87 | } 88 | }; 89 | 90 | } // namespace detail 91 | } // namespace block_cyphers 92 | } // namespace hashes 93 | } // namespace boost 94 | 95 | #endif // BOOST_HASH_BLOCK_CYPHERS_DETAIL_SHACAL_FUNCTIONS_HPP 96 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/block_cyphers/detail/shacal_policy.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_BLOCK_CYPHERS_DETAIL_SHACAL_POLICY_HPP 10 | #define BOOST_HASH_BLOCK_CYPHERS_DETAIL_SHACAL_POLICY_HPP 11 | 12 | #include 13 | #include 14 | 15 | namespace boost { 16 | namespace hashes { 17 | namespace block_cyphers { 18 | namespace detail { 19 | 20 | struct shacal_policy : shacal_functions { 21 | 22 | static unsigned const block_words = 5; 23 | static unsigned const block_bits = block_words*word_bits; 24 | typedef array block_type; 25 | 26 | static unsigned const key_words = 16; 27 | static unsigned const key_bits = key_words*word_bits; 28 | typedef array key_type; 29 | 30 | static unsigned const rounds = 80; 31 | typedef array schedule_type; 32 | typedef array constants_type; 33 | 34 | static word_type constant(unsigned t) { 35 | static constants_type const constants = {{ 36 | 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999, 37 | 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999, 38 | 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999, 39 | 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999, 40 | 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999, 41 | 42 | 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 43 | 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 44 | 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 45 | 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 46 | 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 47 | 48 | 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 49 | 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 50 | 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 51 | 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 52 | 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 53 | 54 | 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 55 | 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 56 | 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 57 | 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 58 | 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 59 | }}; 60 | return constants[t]; 61 | } 62 | 63 | }; 64 | 65 | typedef shacal_policy shacal0_policy; 66 | 67 | } // namespace detail 68 | } // namespace block_cyphers 69 | } // namespace hashes 70 | } // namespace boost 71 | 72 | #endif // BOOST_HASH_BLOCK_CYPHERS_DETAIL_SHACAL_POLICY_HPP 73 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/block_cyphers/shacal.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_BLOCK_CYPHERS_SHACAL_HPP 10 | #define BOOST_HASH_BLOCK_CYPHERS_SHACAL_HPP 11 | 12 | #include 13 | 14 | // 15 | // Implemented directly from the SHA standard as found at 16 | // http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf 17 | // 18 | // In SHA terminology: 19 | // - plaintext = H^(i-1) 20 | // - cyphertext = H^(i) 21 | // - key = M^(i) 22 | // - schedule = W 23 | // 24 | 25 | namespace boost { 26 | namespace hashes { 27 | namespace block_cyphers { 28 | 29 | // The original FIPS-180 seems to be gone, but FIPS 180-1 30 | // (http://www.itl.nist.gov/fipspubs/fip180-1.htm) says the only change 31 | // in SHA-1 from SHA(-0) is the rotation in the key scheduling. 32 | class shacal : public basic_shacal { 33 | public: 34 | shacal(key_type const &k) 35 | : basic_shacal(build_schedule(k)) {} 36 | shacal(schedule_type s) 37 | : basic_shacal((prepare_schedule(s), s)) {} 38 | private: 39 | static schedule_type 40 | build_schedule(key_type const &key) { 41 | // Copy key into beginning of schedule 42 | schedule_type schedule; 43 | for (unsigned t = 0; t < key_words; ++t) { 44 | schedule[t] = key[t]; 45 | } 46 | prepare_schedule(schedule); 47 | return schedule; 48 | } 49 | static void 50 | prepare_schedule(schedule_type &schedule) { 51 | #ifdef BOOST_HASH_SHOW_PROGRESS 52 | for (unsigned t = 0; t < key_words; ++t) { 53 | std::printf(word_bits == 32 ? 54 | "W[%2d] = %.8x\n" : 55 | "W[%2d] = %.16lx\n", 56 | t, schedule[t]); 57 | } 58 | #endif 59 | 60 | for (unsigned t = key_words; t < rounds; ++t) { 61 | schedule[t] = schedule[t-3] 62 | ^ schedule[t-8] 63 | ^ schedule[t-14] 64 | ^ schedule[t-16]; 65 | } 66 | } 67 | }; 68 | typedef shacal shacal0; 69 | 70 | } // namespace block_cyphers 71 | } // namespace hashes 72 | } // namespace boost 73 | 74 | #endif // BOOST_HASH_BLOCK_CYPHERS_SHACAL_HPP 75 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/block_cyphers/shacal1.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_BLOCK_CYPHERS_SHACAL1_HPP 10 | #define BOOST_HASH_BLOCK_CYPHERS_SHACAL1_HPP 11 | 12 | #include 13 | 14 | // 15 | // Implemented directly from the SHA standard as found at 16 | // http://csrc.nist.gov/publications/fips/fips180-2/fips180-2.pdf 17 | // 18 | // In SHA terminology: 19 | // - plaintext = H^(i-1) 20 | // - cyphertext = H^(i) 21 | // - key = M^(i) 22 | // - schedule = W 23 | // 24 | 25 | namespace boost { 26 | namespace hashes { 27 | namespace block_cyphers { 28 | 29 | class shacal1 : public basic_shacal { 30 | public: 31 | shacal1(key_type const &k) 32 | : basic_shacal(build_schedule(k)) {} 33 | shacal1(schedule_type s) 34 | : basic_shacal((prepare_schedule(s), s)) {} 35 | private: 36 | static schedule_type 37 | build_schedule(key_type const &key) { 38 | // Copy key into beginning of schedule 39 | schedule_type schedule; 40 | for (unsigned t = 0; t < key_words; ++t) { 41 | schedule[t] = key[t]; 42 | } 43 | prepare_schedule(schedule); 44 | return schedule; 45 | } 46 | static void 47 | prepare_schedule(schedule_type &schedule) { 48 | #ifdef BOOST_HASH_SHOW_PROGRESS 49 | for (unsigned t = 0; t < key_words; ++t) { 50 | std::printf(word_bits == 32 ? 51 | "W[%2d] = %.8x\n" : 52 | "W[%2d] = %.16lx\n", 53 | t, schedule[t]); 54 | } 55 | #endif 56 | 57 | for (unsigned t = key_words; t < rounds; ++t) { 58 | schedule[t] = schedule[t-3] 59 | ^ schedule[t-8] 60 | ^ schedule[t-14] 61 | ^ schedule[t-16]; 62 | schedule[t] = policy_type::ROTL<1>(schedule[t]); 63 | } 64 | } 65 | }; 66 | 67 | } // namespace block_cyphers 68 | } // namespace hashes 69 | } // namespace boost 70 | 71 | #endif // BOOST_HASH_BLOCK_CYPHERS_SHACAL1_HPP 72 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/crc.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_CRC_HPP 10 | #define BOOST_HASH_CRC_HPP 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #include 19 | 20 | #ifdef BOOST_HASH_SHOW_PROGRESS 21 | #include 22 | #endif 23 | 24 | namespace boost { 25 | namespace hashes { 26 | 27 | // Boost.CRC undefs this, so re-define it 28 | #define BOOST_CRC_PARM_TYPE typename ::boost::uint_t::fast 29 | 30 | template 33 | class basic_crc { 34 | public: 35 | typedef crc_optimal crc_computer; 38 | typedef typename crc_computer::value_type word_type; 39 | 40 | static unsigned const value_bits = CHAR_BIT; 41 | typedef typename uint_t::least value_type; 42 | 43 | BOOST_STATIC_ASSERT(Bits >= value_bits); 44 | 45 | static unsigned const digest_bits = Bits; 46 | typedef hashes::digest digest_type; 47 | 48 | public: 49 | basic_crc() { reset(); } 50 | void reset() { crc_.reset(); } 51 | 52 | digest_type digest() const { 53 | word_type x = crc_.checksum(); 54 | digest_type d; 55 | // TODO: Justify bit order 56 | pack_n(&x, 1, 59 | d.data(), digest_bits/octet_bits); 60 | return d; 61 | } 62 | 63 | digest_type end_message() { 64 | digest_type d = digest(); 65 | reset(); 66 | return d; 67 | } 68 | 69 | public: 70 | basic_crc & 71 | update_one(value_type x) { 72 | #ifdef BOOST_HASH_SHOW_PROGRESS 73 | printf("%.8lx + %.2x ==> ", (long)crc_.checksum(), (int)x); 74 | #endif 75 | crc_.process_byte(x); 76 | #ifdef BOOST_HASH_SHOW_PROGRESS 77 | printf("%.8lx\n", (long)crc_.checksum()); 78 | #endif 79 | return *this; 80 | } 81 | 82 | template 83 | basic_crc & 84 | update_n(IterT p, size_t n) { 85 | while (n--) update_one(*p++); 86 | return *this; 87 | } 88 | #ifndef BOOST_HASH_NO_OPTIMIZATION 89 | template 90 | basic_crc & 91 | update_n(ValT const *p, size_t n) { 92 | if (sizeof(ValT) == 1) { 93 | crc_.process_bytes(p, n); 94 | } else { 95 | while (n--) update_one(*p++); 96 | } 97 | return *this; 98 | } 99 | template 100 | basic_crc & 101 | update_n(ValT *p, size_t n) { 102 | return update_n((ValT const *)p, n); 103 | } 104 | #endif 105 | 106 | template 107 | basic_crc & 108 | update(IterT b, IterT e, std::random_access_iterator_tag) { 109 | return update_n(b, e-b); 110 | } 111 | template 112 | basic_crc & 113 | update(IterT b, IterT e, Category) { 114 | while (b != e) update_one(*b++); 115 | return *this; 116 | } 117 | template 118 | basic_crc & 119 | update(IterT b, IterT e) { 120 | typedef typename std::iterator_traits::iterator_category cat; 121 | return update(b, e, cat()); 122 | } 123 | 124 | private: 125 | crc_computer crc_; 126 | }; 127 | 128 | template 131 | struct crc { 132 | private: 133 | typedef basic_crc 134 | octet_hash_type; 135 | public: 136 | template 137 | struct stream_hash { 138 | BOOST_STATIC_ASSERT(value_bits == CHAR_BIT); 139 | typedef octet_hash_type type_; 140 | #ifdef BOOST_HASH_NO_HIDE_INTERNAL_TYPES 141 | typedef type_ type; 142 | #else 143 | struct type : type_ {}; 144 | #endif 145 | }; 146 | typedef typename octet_hash_type::digest_type digest_type; 147 | }; 148 | 149 | // http://www.libpng.org/pub/png/spec/1.2/PNG-Structure.html#CRC-algorithm 150 | typedef crc<32, 0x04C11DB7, 0xFFFFFFFF, 0xFFFFFFFF, true, true> crc32_png; 151 | 152 | } // namespace hashes 153 | } // namespace boost 154 | 155 | #endif // BOOST_HASH_CRC_HPP 156 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/cubehash.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_CUBEHASH_HPP 10 | #define BOOST_HASH_CUBEHASH_HPP 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | // As of 2009-07-15, the submission to NIST for SHA-3 is CubeHash16/32 17 | // http://cubehash.cr.yp.to/submission/tweak.pdf 18 | #ifndef BOOST_HASH_CUBEHASH_DEFAULT_R 19 | #define BOOST_HASH_CUBEHASH_DEFAULT_R 16 20 | #endif 21 | #ifndef BOOST_HASH_CUBEHASH_DEFAULT_B 22 | #define BOOST_HASH_CUBEHASH_DEFAULT_B 32 23 | #endif 24 | 25 | namespace boost { 26 | namespace hashes { 27 | 28 | template 29 | struct cubehash_compressor { 30 | public: 31 | typedef detail::cubehash_policy policy_type; 32 | 33 | static unsigned const word_bits = policy_type::word_bits; 34 | typedef typename policy_type::word_type word_type; 35 | 36 | static unsigned const state_bits = policy_type::state_bits; 37 | static unsigned const state_words = policy_type::state_words; 38 | typedef typename policy_type::state_type state_type; 39 | 40 | static unsigned const block_bits = policy_type::block_bits; 41 | static unsigned const block_words = policy_type::block_words; 42 | typedef typename policy_type::block_type block_type; 43 | 44 | public: 45 | void 46 | operator()(state_type &state, 47 | block_type const &block) { 48 | process_block(state, block); 49 | } 50 | 51 | private: 52 | static void 53 | process_block(state_type &state, 54 | block_type const &block) { 55 | #ifdef BOOST_HASH_SHOW_PROGRESS 56 | printf("Xoring the following block to the state:\n"); 57 | for (unsigned i = 0; i < block.size(); ++i) { 58 | printf("%.8x%c", block[i], (i+1) != block.size() ? ' ' : '\n'); 59 | } 60 | #endif 61 | for (unsigned i = 0; i < block_words; ++i) { 62 | state[i] ^= block[i]; 63 | } 64 | policy_type::transform_r(state); 65 | } 66 | 67 | }; 68 | 69 | template 70 | struct cubehash_finalizer { 71 | typedef detail::cubehash_policy policy_type; 72 | typedef typename policy_type::state_type state_type; 73 | void operator()(state_type &state) const { 74 | state[31] ^= 1; 75 | policy_type::transform_10r(state); 76 | } 77 | }; 78 | 79 | // 80 | // If the second and third parameters are unspecified (or left 0), then 81 | // the first parameter is the number of bits in the digest, and 82 | // r and b will be set to defaults. 83 | // 84 | // Otherwise the three parameters are r, b, and h respectively. 85 | // 86 | 87 | template 88 | struct cubehash; 89 | 90 | template 91 | struct cubehash { 92 | private: 93 | typedef detail::cubehash_policy policy_type; 94 | public: 95 | typedef merkle_damgard_block_hash< 96 | stream_endian::little_octet_big_bit, 97 | policy_type::digest_bits, 98 | typename policy_type::iv_generator, 99 | cubehash_compressor, 100 | cubehash_finalizer 101 | > block_hash_type_; 102 | #ifdef BOOST_HASH_NO_HIDE_INTERNAL_TYPES 103 | typedef block_hash_type_ block_hash_type; 104 | #else 105 | struct block_hash_type : block_hash_type_ {}; 106 | #endif 107 | template 108 | struct stream_hash { 109 | typedef stream_preprocessor< 110 | stream_endian::little_octet_big_bit, 111 | value_bits, 112 | 0, // No length padding! 113 | block_hash_type 114 | > type_; 115 | #ifdef BOOST_HASH_NO_HIDE_INTERNAL_TYPES 116 | typedef type_ type; 117 | #else 118 | struct type : type_ {}; 119 | #endif 120 | }; 121 | typedef typename block_hash_type::digest_type digest_type; 122 | }; 123 | 124 | template 125 | struct cubehash 126 | : cubehash {}; 129 | 130 | } // namespace hashes 131 | } // namespace boost 132 | 133 | #endif // BOOST_HASH_CUBEHASH_HPP 134 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/davies_meyer_compressor.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_DAVIES_MEYER_COMPRESSOR_HPP 10 | #define BOOST_HASH_DAVIES_MEYER_COMPRESSOR_HPP 11 | 12 | namespace boost { 13 | namespace hashes { 14 | 15 | // 16 | // The Davies-Meyer construction turns a block cypher 17 | // into a one-way compression function 18 | // 19 | // http://en.wikipedia.org/wiki/One-way_compression_function#Davies-Meyer 20 | // 21 | 22 | template 23 | struct davies_meyer_compressor { 24 | public: 25 | typedef block_cypher_T block_cypher_type; 26 | 27 | static unsigned const word_bits = block_cypher_type::word_bits; 28 | typedef typename block_cypher_type::word_type word_type; 29 | 30 | static unsigned const state_bits = block_cypher_type::block_bits; 31 | static unsigned const state_words = block_cypher_type::block_words; 32 | typedef typename block_cypher_type::block_type state_type; 33 | 34 | static unsigned const block_bits = block_cypher_type::key_bits; 35 | static unsigned const block_words = block_cypher_type::key_words; 36 | typedef typename block_cypher_type::key_type block_type; 37 | 38 | public: 39 | void 40 | operator()(state_type &state, 41 | block_type const &block) { 42 | process_block(state, block); 43 | } 44 | 45 | private: 46 | static void 47 | process_block(state_type &state, 48 | block_type const &block) { 49 | block_cypher_type cypher(block); 50 | state_type new_state = cypher.encypher((state_type const &)state); 51 | combine_F f; 52 | f(state, new_state); 53 | } 54 | }; 55 | 56 | } // namespace hashes 57 | } // namespace boost 58 | 59 | #endif // BOOST_HASH_DAVIES_MEYER_COMPRESSOR_HPP 60 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/detail/basic_functions.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_DETAIL_BASIC_FUNCTIONS_HPP 10 | #define BOOST_HASH_DETAIL_BASIC_FUNCTIONS_HPP 11 | 12 | #include 13 | 14 | namespace boost { 15 | namespace hashes { 16 | namespace detail { 17 | 18 | using block_cyphers::detail::basic_functions; 19 | 20 | } // namespace detail 21 | } // namespace hashes 22 | } // namespace boost 23 | 24 | #endif // BOOST_HASH_DETAIL_BASIC_FUNCTIONS_HPP 25 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/detail/md4_policy.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_DETAIL_MD4_POLICY_HPP 10 | #define BOOST_HASH_DETAIL_MD4_POLICY_HPP 11 | 12 | #include 13 | #include 14 | 15 | namespace boost { 16 | namespace hashes { 17 | namespace detail { 18 | 19 | struct md4_policy { 20 | 21 | typedef block_cyphers::detail::md4_policy cypher_policy; 22 | typedef cypher_policy::block_type state_type; 23 | 24 | static unsigned const digest_bits = cypher_policy::block_bits; 25 | typedef digest digest_type; 26 | 27 | struct iv_generator { 28 | state_type const & 29 | operator()() const { 30 | static state_type const H0 = {{ 31 | 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 32 | }}; 33 | return H0; 34 | } 35 | }; 36 | 37 | }; 38 | 39 | } // namespace detail 40 | } // namespace hashes 41 | } // namespace boost 42 | 43 | #endif // BOOST_HASH_DETAIL_MD4_POLICY_HPP 44 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/detail/md5_policy.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_DETAIL_MD5_POLICY_HPP 10 | #define BOOST_HASH_DETAIL_MD5_POLICY_HPP 11 | 12 | #include 13 | #include 14 | 15 | namespace boost { 16 | namespace hashes { 17 | namespace detail { 18 | 19 | struct md5_policy { 20 | 21 | typedef block_cyphers::detail::md5_policy cypher_policy; 22 | typedef cypher_policy::block_type state_type; 23 | 24 | static unsigned const digest_bits = cypher_policy::block_bits; 25 | typedef digest digest_type; 26 | 27 | struct iv_generator { 28 | state_type const & 29 | operator()() const { 30 | // Same as MD4 31 | static state_type const H0 = {{ 32 | 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 33 | }}; 34 | return H0; 35 | } 36 | }; 37 | 38 | }; 39 | 40 | } // namespace detail 41 | } // namespace hashes 42 | } // namespace boost 43 | 44 | #endif // BOOST_HASH_DETAIL_MD5_POLICY_HPP 45 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/detail/primes.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_DETAIL_PRIMES_HPP 10 | #define BOOST_HASH_DETAIL_PRIMES_HPP 11 | 12 | #include 13 | 14 | namespace boost { 15 | namespace hashes { 16 | namespace detail { 17 | 18 | template 19 | struct all_ones { 20 | typedef typename uint_t::least type; 21 | static type const value = (type(all_ones::value) << 1) | 1; 22 | }; 23 | template <> 24 | struct all_ones<0> { 25 | typedef uint_t<0>::least type; 26 | static type const value = 0; 27 | }; 28 | 29 | template 30 | struct largest_prime; 31 | 32 | #define BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(B, D) \ 33 | template <> \ 34 | struct largest_prime { \ 35 | static uint_t::least const value = all_ones::value - D; \ 36 | } 37 | 38 | // http://primes.utm.edu/lists/2small/0bit.html or 39 | // http://www.research.att.com/~njas/sequences/A013603 40 | // Though those offets are from 2**b; This code is offsets from 2**b-1 41 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET( 2, 0); 42 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET( 3, 0); 43 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET( 4, 2); 44 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET( 5, 0); 45 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET( 6, 2); 46 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET( 7, 0); 47 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET( 8, 4); 48 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET( 9, 2); 49 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(10, 2); 50 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(11, 8); 51 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(12, 2); 52 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(13, 0); 53 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(14, 2); 54 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(15, 18); 55 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(16, 14); 56 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(17, 0); 57 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(18, 4); 58 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(19, 0); 59 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(20, 2); 60 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(21, 8); 61 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(22, 2); 62 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(23, 14); 63 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(24, 2); 64 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(25, 38); 65 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(26, 4); 66 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(27, 38); 67 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(28, 56); 68 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(29, 2); 69 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(30, 34); 70 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(31, 0); 71 | BOOST_HASH_DEFINE_LARGEST_PRIME_BY_OFFSET(32, 4); 72 | 73 | } // namespace detail 74 | } // namespace hashes 75 | } // namespace boost 76 | 77 | #endif // BOOST_HASH_DETAIL_PRIMES_HPP 78 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/detail/sha1_policy.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_DETAIL_SHA1_POLICY_HPP 10 | #define BOOST_HASH_DETAIL_SHA1_POLICY_HPP 11 | 12 | #include 13 | 14 | namespace boost { 15 | namespace hashes { 16 | namespace detail { 17 | 18 | typedef sha_policy sha1_policy; 19 | 20 | } // namespace detail 21 | } // namespace hashes 22 | } // namespace boost 23 | 24 | #endif // BOOST_HASH_DETAIL_SHA1_POLICY_HPP 25 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/detail/sha2_policy.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_DETAIL_SHA2_POLICY_HPP 10 | #define BOOST_HASH_DETAIL_SHA2_POLICY_HPP 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | namespace boost { 18 | namespace hashes { 19 | namespace detail { 20 | 21 | template 22 | struct basic_sha2_policy { 23 | 24 | static unsigned const cypher_version = CypherVersion; 25 | 26 | typedef block_cyphers::detail::shacal2_policy cypher_policy; 27 | typedef typename cypher_policy::block_type state_type; 28 | 29 | }; 30 | 31 | template 32 | struct sha2_policy; 33 | 34 | template <> 35 | struct sha2_policy<224> : basic_sha2_policy<256> { 36 | 37 | static unsigned const digest_bits = 224; 38 | typedef digest digest_type; 39 | 40 | struct iv_generator { 41 | state_type const & 42 | operator()() const { 43 | static state_type const H0 = {{ 44 | 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939, 45 | 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4, 46 | }}; 47 | return H0; 48 | } 49 | }; 50 | 51 | }; 52 | 53 | template <> 54 | struct sha2_policy<256> : basic_sha2_policy<256> { 55 | 56 | static unsigned const digest_bits = 256; 57 | typedef digest digest_type; 58 | 59 | struct iv_generator { 60 | state_type const & 61 | operator()() const { 62 | static state_type const H0 = {{ 63 | 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 64 | 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19, 65 | }}; 66 | return H0; 67 | } 68 | }; 69 | 70 | }; 71 | 72 | template <> 73 | struct sha2_policy<384> : basic_sha2_policy<512> { 74 | 75 | static unsigned const digest_bits = 384; 76 | typedef digest digest_type; 77 | 78 | struct iv_generator { 79 | state_type const & 80 | operator()() const { 81 | static state_type const H0 = {{ 82 | UINT64_C(0xcbbb9d5dc1059ed8), UINT64_C(0x629a292a367cd507), 83 | UINT64_C(0x9159015a3070dd17), UINT64_C(0x152fecd8f70e5939), 84 | UINT64_C(0x67332667ffc00b31), UINT64_C(0x8eb44a8768581511), 85 | UINT64_C(0xdb0c2e0d64f98fa7), UINT64_C(0x47b5481dbefa4fa4), 86 | }}; 87 | return H0; 88 | } 89 | }; 90 | 91 | }; 92 | 93 | template <> 94 | struct sha2_policy<512> : basic_sha2_policy<512> { 95 | 96 | static unsigned const digest_bits = 512; 97 | typedef digest digest_type; 98 | 99 | struct iv_generator { 100 | state_type const & 101 | operator()() const { 102 | static state_type const H0 = {{ 103 | UINT64_C(0x6a09e667f3bcc908), UINT64_C(0xbb67ae8584caa73b), 104 | UINT64_C(0x3c6ef372fe94f82b), UINT64_C(0xa54ff53a5f1d36f1), 105 | UINT64_C(0x510e527fade682d1), UINT64_C(0x9b05688c2b3e6c1f), 106 | UINT64_C(0x1f83d9abfb41bd6b), UINT64_C(0x5be0cd19137e2179), 107 | }}; 108 | return H0; 109 | } 110 | }; 111 | 112 | }; 113 | 114 | } // namespace detail 115 | } // namespace hashes 116 | } // namespace boost 117 | 118 | #endif // BOOST_HASH_DETAIL_SHA2_POLICY_HPP 119 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/detail/sha_policy.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_DETAIL_SHA_POLICY_HPP 10 | #define BOOST_HASH_DETAIL_SHA_POLICY_HPP 11 | 12 | #include 13 | #include 14 | 15 | namespace boost { 16 | namespace hashes { 17 | namespace detail { 18 | 19 | struct sha_policy { 20 | 21 | typedef block_cyphers::detail::shacal_policy cypher_policy; 22 | typedef cypher_policy::block_type state_type; 23 | 24 | static unsigned const digest_bits = 160; 25 | typedef digest digest_type; 26 | 27 | struct iv_generator { 28 | state_type const & 29 | operator()() const { 30 | // First 4 words are the same as MD4 31 | static state_type const H0 = {{ 32 | 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 33 | 0xc3d2e1f0, 34 | }}; 35 | return H0; 36 | } 37 | }; 38 | 39 | }; 40 | 41 | typedef sha_policy sha0_policy; 42 | 43 | } // namespace detail 44 | } // namespace hashes 45 | } // namespace boost 46 | 47 | #endif // BOOST_HASH_DETAIL_SHA_POLICY_HPP 48 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/detail/state_adder.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_DETAIL_STATE_ADDER_HPP 10 | #define BOOST_HASH_DETAIL_STATE_ADDER_HPP 11 | 12 | namespace boost { 13 | namespace hashes { 14 | namespace detail { 15 | 16 | struct state_adder { 17 | template 18 | void operator()(T &s1, T const &s2) { 19 | typedef typename T::size_type size_type; 20 | size_type n = (s2.size() < s1.size() ? s2.size() : s1.size()); 21 | for (typename T::size_type i = 0; i < n; ++i) { 22 | s1[i] += s2[i]; 23 | } 24 | } 25 | }; 26 | 27 | } // namespace detail 28 | } // namespace hashes 29 | } // namespace boost 30 | 31 | #endif // BOOST_HASH_DETAIL_STATE_ADDER_HPP 32 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/detail/unbounded_shift.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_DETAIL_UNBOUNDED_SHIFT_HPP 10 | #define BOOST_HASH_DETAIL_UNBOUNDED_SHIFT_HPP 11 | 12 | #include 13 | 14 | namespace boost { 15 | namespace hashes { 16 | namespace detail { 17 | 18 | template 19 | struct unbounded_shifter { 20 | static T shl(T x) { return unbounded_shifter::shl(T(x << 1)); } 21 | static T shr(T x) { return unbounded_shifter::shr(T(x >> 1)); } 22 | }; 23 | template 24 | struct unbounded_shifter<0, T> { 25 | static T shl(T x) { return x; } 26 | static T shr(T x) { return x; } 27 | }; 28 | 29 | template 30 | T unbounded_shl(T x) { 31 | return unbounded_shifter::shl(x); 32 | } 33 | template 34 | T unbounded_shr(T x) { 35 | return unbounded_shifter::shr(x); 36 | } 37 | 38 | template 39 | T low_bits(T x) { 40 | T highmask = unbounded_shl(~T()); 41 | return T(x & ~highmask); 42 | } 43 | 44 | } // namespace detail 45 | } // namespace hashes 46 | } // namespace boost 47 | 48 | #endif // BOOST_HASH_DETAIL_UNBOUNDED_SHIFT_HPP 49 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/digest.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_DIGEST_HPP 10 | #define BOOST_HASH_DIGEST_HPP 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include 17 | 18 | #include 19 | 20 | namespace boost { 21 | namespace hashes { 22 | 23 | unsigned const octet_bits = 8; 24 | typedef uint_t::least octet_type; 25 | 26 | // Always stored internally as a sequence of octets in display order. 27 | // This allows digests from different algorithms to have the same type, 28 | // allowing them to be more easily stored and compared. 29 | template 30 | class digest : public array { 31 | public: 32 | 33 | static unsigned const digest_bits = digest_bits_; 34 | BOOST_STATIC_ASSERT(digest_bits % octet_bits == 0); 35 | static unsigned const digest_octets = digest_bits/octet_bits; 36 | typedef array base_array_type; 37 | 38 | static unsigned const cstring_size = digest_bits/4 + 1; 39 | typedef array cstring_type; 40 | 41 | digest() : base_array_type() {} 42 | digest(base_array_type const &a) : base_array_type(a) {} 43 | 44 | template 45 | oit_T to_ascii(oit_T it) const { 46 | for (unsigned j = 0; j < digest_octets; ++j) { 47 | octet_type b = base_array()[j]; 48 | *it++ = "0123456789abcdef"[(b >> 4) & 0xF]; 49 | *it++ = "0123456789abcdef"[(b >> 0) & 0xF]; 50 | } 51 | return it; 52 | } 53 | 54 | std::string 55 | str() const { 56 | cstring_type cstr = cstring(); 57 | return std::string(cstr.data(), cstr.size()-1); 58 | } 59 | 60 | cstring_type 61 | cstring() const { 62 | cstring_type s; 63 | char *p = to_ascii(s.data()); 64 | *p++ = '\0'; 65 | return s; 66 | } 67 | 68 | base_array_type const &base_array() const { return *this; } 69 | }; 70 | 71 | template 72 | digest 73 | resize(digest const &od) { 74 | digest nd; 75 | unsigned bytes = sizeof(octet_type)*(NDB < ODB ? NDB : ODB)/octet_bits; 76 | std::memcpy(nd.data(), od.data(), bytes); 77 | return nd; 78 | } 79 | 80 | template 81 | digest 82 | truncate(digest const &od) { 83 | BOOST_STATIC_ASSERT(NDB <= ODB); 84 | return resize(od); 85 | } 86 | 87 | template 88 | bool operator==(digest const &a, digest const &b) { 89 | unsigned const DB = DB1 < DB2 ? DB2 : DB1; 90 | return resize(a).base_array() == resize(b).base_array(); 91 | } 92 | template 93 | bool operator!=(digest const &a, digest const &b) { 94 | return !(a == b); 95 | } 96 | 97 | template 98 | bool operator<(digest const &a, digest const &b) { 99 | unsigned const DB = DB1 < DB2 ? DB2 : DB1; 100 | return resize(a).base_array() < resize(b).base_array(); 101 | } 102 | template 103 | bool operator>(digest const &a, digest const &b) { 104 | return b < a; 105 | } 106 | template 107 | bool operator<=(digest const &a, digest const &b) { 108 | return !(b < a); 109 | } 110 | template 111 | bool operator>=(digest const &a, digest const &b) { 112 | return !(b > a); 113 | } 114 | 115 | template 116 | bool operator!=(digest const &a, char const *b) { 117 | BOOST_ASSERT(std::strlen(b) == DB/4); 118 | return std::strcmp(a.cstring().data(), b); 119 | } 120 | template 121 | bool operator==(digest const &a, char const *b) { 122 | return !(a != b); 123 | } 124 | template 125 | bool operator!=(char const *b, digest const &a) { 126 | return a != b; 127 | } 128 | template 129 | bool operator==(char const *b, digest const &a) { 130 | return a == b; 131 | } 132 | 133 | } // namespace hashes 134 | } // namespace boost 135 | 136 | #endif // BOOST_HASH_DIGEST_HPP 137 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/digest_io.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_DIGEST_IO_HPP 10 | #define BOOST_HASH_DIGEST_IO_HPP 11 | 12 | #include 13 | #include 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include 20 | 21 | namespace boost { 22 | namespace hashes { 23 | 24 | template 25 | std::ostream & 26 | operator<<(std::ostream &sink, digest const &d) { 27 | d.to_ascii(std::ostream_iterator(sink)); 28 | return sink; 29 | }; 30 | 31 | template 32 | std::istream & 33 | operator>>(std::istream &source, digest &d) { 34 | boost::array a = {{}}; 35 | for (unsigned i = 0; i < a.size(); ++i) { 36 | char c; 37 | if (!source.get(c)) { 38 | source.setstate(std::ios::failbit); 39 | break; 40 | } 41 | if (!std::isxdigit(c, source.getloc())) { 42 | source.unget(); 43 | source.setstate(std::ios::failbit); 44 | break; 45 | } 46 | 47 | if (std::isdigit(c, source.getloc())) { 48 | a[i] = (c - '0'); 49 | } else { 50 | a[i] = std::toupper(c, source.getloc()) - 'A' + 0xA; 51 | } 52 | } 53 | pack(a, d); 54 | return source; 55 | }; 56 | 57 | } // namespace hashes 58 | } // namespace boost 59 | 60 | #endif // BOOST_HASH_DIGEST_IO_HPP 61 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/md4.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_MD4_HPP 10 | #define BOOST_HASH_MD4_HPP 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace boost { 20 | namespace hashes { 21 | 22 | struct md4 { 23 | private: 24 | typedef detail::md4_policy policy_type; 25 | typedef block_cyphers::md4 block_cypher_type; 26 | public: 27 | typedef merkle_damgard_block_hash< 28 | stream_endian::little_octet_big_bit, 29 | policy_type::digest_bits, 30 | policy_type::iv_generator, 31 | davies_meyer_compressor 33 | > block_hash_type_; 34 | #ifdef BOOST_HASH_NO_HIDE_INTERNAL_TYPES 35 | typedef block_hash_type_ block_hash_type; 36 | #else 37 | struct block_hash_type : block_hash_type_ {}; 38 | #endif 39 | template 40 | struct stream_hash { 41 | typedef stream_preprocessor< 42 | stream_endian::little_octet_big_bit, 43 | value_bits, 44 | block_hash_type::word_bits * 2, 45 | block_hash_type 46 | > type_; 47 | #ifdef BOOST_HASH_NO_HIDE_INTERNAL_TYPES 48 | typedef type_ type; 49 | #else 50 | struct type : type_ {}; 51 | #endif 52 | }; 53 | typedef block_hash_type::digest_type digest_type; 54 | }; 55 | 56 | } // namespace hashes 57 | } // namespace boost 58 | 59 | #endif // BOOST_HASH_MD4_HPP 60 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/md5.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_MD5_HPP 10 | #define BOOST_HASH_MD5_HPP 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace boost { 20 | namespace hashes { 21 | 22 | struct md5 { 23 | private: 24 | typedef detail::md5_policy policy_type; 25 | typedef block_cyphers::md5 block_cypher_type; 26 | public: 27 | typedef merkle_damgard_block_hash< 28 | stream_endian::little_octet_big_bit, 29 | policy_type::digest_bits, 30 | policy_type::iv_generator, 31 | davies_meyer_compressor 33 | > block_hash_type_; 34 | #ifdef BOOST_HASH_NO_HIDE_INTERNAL_TYPES 35 | typedef block_hash_type_ block_hash_type; 36 | #else 37 | struct block_hash_type : block_hash_type_ {}; 38 | #endif 39 | template 40 | struct stream_hash { 41 | typedef stream_preprocessor< 42 | stream_endian::little_octet_big_bit, 43 | value_bits, 44 | block_hash_type::word_bits * 2, 45 | block_hash_type 46 | > type_; 47 | #ifdef BOOST_HASH_NO_HIDE_INTERNAL_TYPES 48 | typedef type_ type; 49 | #else 50 | struct type : type_ {}; 51 | #endif 52 | }; 53 | typedef block_hash_type::digest_type digest_type; 54 | }; 55 | 56 | } // namespace hashes 57 | } // namespace boost 58 | 59 | #endif // BOOST_HASH_MD5_HPP 60 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/merkle_damgard_block_hash.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_MERKLE_DAMGARD_BLOCK_HASH_HPP 10 | #define BOOST_HASH_MERKLE_DAMGARD_BLOCK_HASH_HPP 11 | 12 | #include 13 | #include 14 | 15 | namespace boost { 16 | namespace hashes { 17 | 18 | // 19 | // The Merkle-Damgård construction builds a block hash from a 20 | // one-way compressor. As this version operated on the block 21 | // level, it doesn't contain any padding or other strengthening. 22 | // For a Wide Pipe construction, use a digest_type that will 23 | // truncate the internal state. 24 | // 25 | 26 | struct nop_finalizer { 27 | template 28 | void 29 | operator()(T &) {} 30 | }; 31 | 32 | template 37 | class merkle_damgard_block_hash { 38 | public: 39 | typedef hashes::digest digest_type; 40 | 41 | typedef iv_G iv_generator; 42 | typedef compressor_F compressor_functor; 43 | typedef finalizer_F finalizer_functor; 44 | 45 | static unsigned const word_bits = compressor_functor::word_bits; 46 | typedef typename compressor_functor::word_type word_type; 47 | 48 | static unsigned const state_bits = compressor_functor::state_bits; 49 | static unsigned const state_words = compressor_functor::state_words; 50 | typedef typename compressor_functor::state_type state_type; 51 | 52 | static unsigned const block_bits = compressor_functor::block_bits; 53 | static unsigned const block_words = compressor_functor::block_words; 54 | typedef typename compressor_functor::block_type block_type; 55 | 56 | public: 57 | merkle_damgard_block_hash &update(block_type const &block) { 58 | compressor_functor compressor; 59 | compressor(state_, block); 60 | return *this; 61 | } 62 | digest_type end_message() { 63 | finalizer_functor finalizer; 64 | finalizer(state_); 65 | digest_type d; 66 | pack_n(state_.data(), digest_bits/word_bits, 69 | d.data(), digest_bits/octet_bits); 70 | reset(); 71 | return d; 72 | } 73 | digest_type digest() const { 74 | return merkle_damgard_block_hash(*this).end_message(); 75 | } 76 | 77 | public: 78 | merkle_damgard_block_hash() { reset(); } 79 | void reset(state_type const &s) { state_ = s; } 80 | void reset() { 81 | iv_generator iv; 82 | reset(iv()); 83 | } 84 | state_type const &state() const { return state_; } 85 | private: 86 | state_type state_; 87 | }; 88 | 89 | } // namespace hashes 90 | } // namespace boost 91 | 92 | #endif // BOOST_HASH_MERKLE_DAMGARD_BLOCK_HASH_HPP 93 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/sha.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_SHA_HPP 10 | #define BOOST_HASH_SHA_HPP 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace boost { 20 | namespace hashes { 21 | 22 | struct sha { 23 | private: 24 | typedef detail::sha_policy policy_type; 25 | typedef block_cyphers::shacal block_cypher_type; 26 | public: 27 | typedef merkle_damgard_block_hash< 28 | stream_endian::big_octet_big_bit, 29 | policy_type::digest_bits, 30 | policy_type::iv_generator, 31 | davies_meyer_compressor 33 | > block_hash_type_; 34 | #ifdef BOOST_HASH_NO_HIDE_INTERNAL_TYPES 35 | typedef block_hash_type_ block_hash_type; 36 | #else 37 | struct block_hash_type : block_hash_type_ {}; 38 | #endif 39 | template 40 | struct stream_hash { 41 | typedef stream_preprocessor< 42 | stream_endian::big_octet_big_bit, 43 | value_bits, 44 | block_hash_type::word_bits * 2, 45 | block_hash_type 46 | > type_; 47 | #ifdef BOOST_HASH_NO_HIDE_INTERNAL_TYPES 48 | typedef type_ type; 49 | #else 50 | struct type : type_ {}; 51 | #endif 52 | }; 53 | typedef block_hash_type::digest_type digest_type; 54 | }; 55 | typedef sha sha0; 56 | 57 | } // namespace hashes 58 | } // namespace boost 59 | 60 | #endif // BOOST_HASH_SHA_HPP 61 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/sha1.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_SHA1_HPP 10 | #define BOOST_HASH_SHA1_HPP 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace boost { 20 | namespace hashes { 21 | 22 | struct sha1 { 23 | private: 24 | typedef detail::sha1_policy policy_type; 25 | typedef block_cyphers::shacal1 block_cypher_type; 26 | public: 27 | typedef merkle_damgard_block_hash< 28 | stream_endian::big_octet_big_bit, 29 | policy_type::digest_bits, 30 | policy_type::iv_generator, 31 | davies_meyer_compressor 33 | > block_hash_type_; 34 | #ifdef BOOST_HASH_NO_HIDE_INTERNAL_TYPES 35 | typedef block_hash_type_ block_hash_type; 36 | #else 37 | struct block_hash_type : block_hash_type_ {}; 38 | #endif 39 | template 40 | struct stream_hash { 41 | typedef stream_preprocessor< 42 | stream_endian::big_octet_big_bit, 43 | value_bits, 44 | block_hash_type::word_bits * 2, 45 | block_hash_type 46 | > type_; 47 | #ifdef BOOST_HASH_NO_HIDE_INTERNAL_TYPES 48 | typedef type_ type; 49 | #else 50 | struct type : type_ {}; 51 | #endif 52 | }; 53 | typedef block_hash_type::digest_type digest_type; 54 | }; 55 | 56 | } // namespace hashes 57 | } // namespace boost 58 | 59 | #endif // BOOST_HASH_SHA1_HPP 60 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/sha2.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_SHA2_HPP 10 | #define BOOST_HASH_SHA2_HPP 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | namespace boost { 20 | namespace hashes { 21 | 22 | template 23 | struct sha2 { 24 | private: 25 | typedef detail::sha2_policy policy_type; 26 | typedef block_cyphers::shacal2 27 | block_cypher_type; 28 | public: 29 | typedef merkle_damgard_block_hash< 30 | stream_endian::big_octet_big_bit, 31 | policy_type::digest_bits, 32 | typename policy_type::iv_generator, 33 | davies_meyer_compressor 35 | > block_hash_type_; 36 | #ifdef BOOST_HASH_NO_HIDE_INTERNAL_TYPES 37 | typedef block_hash_type_ block_hash_type; 38 | #else 39 | struct block_hash_type : block_hash_type_ {}; 40 | #endif 41 | template 42 | struct stream_hash { 43 | typedef stream_preprocessor< 44 | stream_endian::big_octet_big_bit, 45 | value_bits, 46 | block_hash_type::word_bits * 2, 47 | block_hash_type 48 | > type_; 49 | #ifdef BOOST_HASH_NO_HIDE_INTERNAL_TYPES 50 | typedef type_ type; 51 | #else 52 | struct type : type_ {}; 53 | #endif 54 | }; 55 | typedef typename block_hash_type::digest_type digest_type; 56 | }; 57 | 58 | } // namespace hashes 59 | } // namespace boost 60 | 61 | #endif // BOOST_HASH_SHA2_HPP 62 | -------------------------------------------------------------------------------- /avboost/include/boost/hash/stream_endian.hpp: -------------------------------------------------------------------------------- 1 |  2 | // 3 | // Copyright 2010 Scott McMurray. 4 | // Distributed under the Boost Software License, Version 1.0. 5 | // (See accompanying file LICENSE_1_0.txt or copy at 6 | // http://www.boost.org/LICENSE_1_0.txt) 7 | // 8 | 9 | #ifndef BOOST_HASH_STREAM_ENDIAN_HPP 10 | #define BOOST_HASH_STREAM_ENDIAN_HPP 11 | 12 | #include 13 | 14 | #include 15 | 16 | namespace boost { 17 | namespace hashes { 18 | 19 | namespace stream_endian { 20 | 21 | // General versions; There should be no need to use these directly 22 | 23 | template 24 | struct big_unit_big_bit {}; 25 | template 26 | struct little_unit_little_bit {}; 27 | template 28 | struct big_unit_little_bit {}; 29 | template 30 | struct little_unit_big_bit {}; 31 | template 32 | struct host_unit { BOOST_STATIC_ASSERT(UnitBits % CHAR_BIT == 0); }; 33 | 34 | // Typical, useful instantiations 35 | 36 | typedef big_unit_big_bit<1> big_bit; 37 | typedef big_unit_big_bit big_byte_big_bit; 38 | typedef big_unit_big_bit<8> big_octet_big_bit; 39 | 40 | typedef little_unit_little_bit<1> little_bit; 41 | typedef little_unit_little_bit little_byte_little_bit; 42 | typedef little_unit_little_bit<8> little_octet_little_bit; 43 | 44 | typedef big_unit_little_bit big_byte_little_bit; 45 | typedef big_unit_little_bit<8> big_octet_little_bit; 46 | 47 | typedef little_unit_big_bit little_byte_big_bit; 48 | typedef little_unit_big_bit<8> little_octet_big_bit; 49 | 50 | typedef host_unit host_byte; 51 | 52 | } 53 | 54 | } // namespace hashes 55 | } // namespace boost 56 | 57 | #endif // BOOST_HASH_STREAM_ENDIAN_HPP 58 | -------------------------------------------------------------------------------- /avboost/include/boost/ietf/README.md: -------------------------------------------------------------------------------- 1 | boost.ietf 2 | 3 | 这里打算收集所有的 IETF RFC标准的Boost风格实现,除了那些已经被 avhttp 实现的部分。当然未来可能是将 avhttp 并进来。 4 | 5 | 近期要实现的标准有 电子邮件。 6 | 7 | 8 | -------------------------------------------------------------------------------- /avboost/include/boost/invoke_wrapper.hpp: -------------------------------------------------------------------------------- 1 |  2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace boost{ 10 | namespace invoke_wrapper{ 11 | 12 | template 13 | class invoke_once; 14 | 15 | #define SV_TEXT(z, n, text) text ## n 16 | #define SV_ARG(z, n, _) Arg ## n arg ## n 17 | 18 | #define SINGLE_INVOKER(z, n, _) \ 19 | template \ 20 | struct invoke_once \ 21 | { \ 22 | typedef R(Signature)(BOOST_PP_ENUM(BOOST_PP_INC(n), SV_TEXT, Arg)); \ 23 | boost::shared_ptr m_invoked; \ 24 | boost::shared_ptr< \ 25 | boost::function \ 26 | > m_handler; \ 27 | \ 28 | invoke_once(std::function _handler) \ 29 | : m_handler(boost::make_shared< boost::function >(_handler)) \ 30 | , m_invoked(boost::make_shared(false)) \ 31 | {} \ 32 | \ 33 | R operator()(BOOST_PP_ENUM(BOOST_PP_INC(n), SV_ARG, nil)) \ 34 | { \ 35 | if(!*m_invoked) \ 36 | { \ 37 | *m_invoked = true; \ 38 | (*m_handler)(BOOST_PP_ENUM(BOOST_PP_INC(n), SV_TEXT, arg)); \ 39 | } \ 40 | } \ 41 | typedef R result_type; \ 42 | }; 43 | 44 | 45 | BOOST_PP_REPEAT_FROM_TO(0, 10, SINGLE_INVOKER, nil) 46 | 47 | 48 | } // namespcae invoke_wrapper 49 | } // namespace boost 50 | 51 | -------------------------------------------------------------------------------- /avboost/include/boost/logger.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | class tm; 8 | namespace boost{ 9 | 10 | class logger; 11 | 12 | class logger_formater : boost::noncopyable 13 | { 14 | public: 15 | logger_formater(logger& _logger, std::string& level) 16 | : level_(level) 17 | , m_logger(_logger) 18 | {} 19 | 20 | logger_formater(logger_formater&&tmp) 21 | : level_(tmp.level_) 22 | , m_logger(tmp.m_logger) 23 | , oss_(tmp.oss_.str()) 24 | {} 25 | 26 | ~logger_formater(); 27 | 28 | template 29 | logger_formater& operator << (T const& v) 30 | { 31 | oss_ << v; 32 | return *this; 33 | } 34 | 35 | std::ostringstream oss_; 36 | std::string& level_; 37 | logger& m_logger; 38 | }; 39 | 40 | 41 | namespace { 42 | static std::string LOGGER_DEBUG_STR = "DEBUG"; 43 | static std::string LOGGER_INFO_STR = "INFO"; 44 | static std::string LOGGER_WARN_STR = "WARNING"; 45 | static std::string LOGGER_ERR_STR = "ERROR"; 46 | } 47 | 48 | class logger : boost::noncopyable 49 | { 50 | 51 | public: 52 | boost::signals2::signal write_log; 53 | 54 | logger_formater err(){ 55 | return logger_formater(*this, LOGGER_ERR_STR); 56 | } 57 | logger_formater info(){ 58 | return logger_formater(*this, LOGGER_INFO_STR); 59 | } 60 | logger_formater warn(){ 61 | return logger_formater(*this, LOGGER_WARN_STR); 62 | } 63 | 64 | logger_formater dbg(){ 65 | return logger_formater(*this, LOGGER_DEBUG_STR); 66 | } 67 | }; 68 | 69 | inline logger_formater::~logger_formater() 70 | { 71 | std::string message = oss_.str(); 72 | m_logger.write_log(level_, message); 73 | } 74 | 75 | } // namespace 76 | -------------------------------------------------------------------------------- /avboost/include/boost/multihandler.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace boost{ 9 | 10 | 11 | template 12 | class multihandler_op{ 13 | int org_count; 14 | boost::shared_ptr m_count; 15 | Handler m_handler; 16 | public: 17 | multihandler_op(int count, Handler handler ) 18 | : org_count(count), m_count(boost::make_shared(count)), m_handler(handler) 19 | { 20 | } 21 | 22 | 23 | void operator()() 24 | { 25 | -- (*m_count); 26 | if (*m_count==0) 27 | { 28 | m_handler(); 29 | *m_count = org_count; 30 | } 31 | } 32 | 33 | template 34 | void operator()(Arg1 arg1) 35 | { 36 | -- (*m_count); 37 | if (*m_count==0) 38 | { 39 | m_handler(arg1); 40 | *m_count = org_count; 41 | } 42 | } 43 | 44 | template 45 | void operator()(Arg1 arg1, Arg2 arg2) 46 | { 47 | -- (*m_count); 48 | if (*m_count==0) 49 | { 50 | m_handler(arg1, arg2); 51 | *m_count = org_count; 52 | } 53 | } 54 | 55 | }; 56 | 57 | template 58 | multihandler_op bindmultihandler(int count, Handler handler) 59 | { 60 | return multihandler_op(count, handler); 61 | } 62 | 63 | } -------------------------------------------------------------------------------- /avboost/include/boost/splice_stream.hpp: -------------------------------------------------------------------------------- 1 |  2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | namespace boost { 8 | namespace detail { 9 | 10 | template 11 | struct splice_stream_op 12 | { 13 | splice_stream_op(StreamRead &s1, StreamWrite &s2, Handler handler) 14 | : m_read_stream(s1) 15 | , m_write_stream(s2) 16 | , m_handler(handler) 17 | , m_state(0) 18 | , bytes_spliced(0) 19 | , m_streambuf(boost::make_shared()) 20 | { 21 | if (!s1.is_open()) 22 | io_service.post( 23 | bind( 24 | m_handler, 25 | boost::system::errc::make_error_code(boost::system::errc::bad_file_descriptor), 26 | 0 27 | ) 28 | ); 29 | 30 | m_read_stream.async_read_some(m_streambuf->prepare(4096), *this); 31 | } 32 | 33 | void operator()(boost::system::error_code ec, std::size_t bytes_transfered) 34 | { 35 | switch (m_state) 36 | { 37 | case 0: 38 | { 39 | if (!ec) { 40 | m_state = 1; 41 | m_streambuf->commit(bytes_transfered); 42 | // 写入. 43 | return m_write_stream.async_write_some(m_streambuf->data(), *this); 44 | } 45 | if ( ec == boost::asio::error::eof ) 46 | { 47 | m_handler(boost::system::error_code(), bytes_spliced); 48 | }else 49 | { 50 | m_handler(ec, bytes_spliced); 51 | } 52 | } 53 | break; 54 | case 1: 55 | { 56 | m_state = 0; 57 | bytes_spliced += bytes_transfered; 58 | if (!ec) { 59 | m_streambuf->consume(bytes_transfered); 60 | return m_read_stream.async_read_some(m_streambuf->prepare(4096), *this); 61 | } 62 | m_handler(ec, bytes_spliced); 63 | } 64 | } 65 | } 66 | 67 | private: 68 | StreamRead& m_read_stream; 69 | StreamWrite& m_write_stream; 70 | boost::shared_ptr m_streambuf; 71 | Handler m_handler; 72 | 73 | std::size_t bytes_spliced; 74 | 75 | int m_state; 76 | }; 77 | 78 | template 79 | splice_stream_op 80 | make_splice_stream_op(StreamRead &s1, StreamWrite &s2, Handler handler) 81 | { 82 | return splice_stream_op(s1, s2, handler); 83 | } 84 | 85 | } // namespace detail 86 | 87 | // helper functiom 88 | template 89 | void async_splice_stream(StreamRead &s1, StreamWrite &s2, Handler handler) 90 | { 91 | detail::make_splice_stream_op(s1, s2, handler); 92 | } 93 | 94 | template 95 | std::size_t splice_stream(StreamRead &s1, StreamWrite &s2, boost::system::error_code &ec) 96 | { 97 | boost::asio::streambuf buf; 98 | 99 | std::size_t readed = 0; 100 | std::size_t writed = 0; 101 | std::size_t spliced = 0; 102 | 103 | while ( (readed = s1.read_some(buf.prepare(4096), ec)) > 0) 104 | { 105 | buf.commit(readed); 106 | 107 | writed = s2.write_some(buf.data(), ec); 108 | buf.consume(writed); 109 | 110 | if (!ec) 111 | { 112 | spliced+= writed; 113 | } else { 114 | return spliced; 115 | } 116 | } 117 | 118 | return spliced; 119 | } 120 | 121 | 122 | } // namespace boost 123 | -------------------------------------------------------------------------------- /avboost/include/boost/stringencodings.hpp: -------------------------------------------------------------------------------- 1 |  2 | #pragma once 3 | 4 | #ifdef _MSC_VER 5 | #pragma execution_character_set("utf-8") 6 | #endif 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | #if defined(_WIN32) || defined(_WIN64) 13 | #include 14 | #endif 15 | 16 | inline std::string wide_to_utf8(const std::wstring & wstr) 17 | { 18 | #if defined(_WIN32) || defined(_WIN64) 19 | int required_buffer_size = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], wstr.size(), NULL, 0, NULL, NULL); 20 | std::string outstr; 21 | outstr.resize(required_buffer_size); 22 | 23 | int converted_size = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], wstr.size(), &outstr[0], required_buffer_size, NULL, NULL); 24 | outstr.resize(converted_size); 25 | 26 | return outstr; 27 | #else 28 | return boost::locale::conv::utf_to_utf(wstr); 29 | #endif 30 | } 31 | 32 | inline std::string ansi_utf8( std::string const &source, const std::string &characters = "GB18030" ) 33 | { 34 | return boost::locale::conv::between( source, "UTF-8", characters ).c_str(); 35 | } 36 | 37 | // convert wide string for console output aka native encoding 38 | // because mixing std::wcout and std::cout is broken on windows 39 | inline std::string utf8_ansi( std::string const &source, const std::string &characters = "GB18030" ) 40 | { 41 | return boost::locale::conv::between( source, characters, "UTF-8" ).c_str(); 42 | } 43 | 44 | // convert utf8 for console output aka native encoding 45 | // for linux , it does nothing (linux console always use utf8) 46 | // for windows, it convert to CP_ACP 47 | inline std::string utf8_to_local_encode(const std::string & str) 48 | { 49 | #if defined(_WIN32) || defined(_WIN64) 50 | 51 | std::vector wstr; 52 | 53 | int required_buffer_size = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), NULL, 0); 54 | wstr.resize(required_buffer_size); 55 | 56 | wstr.resize(MultiByteToWideChar(CP_UTF8, 0, str.c_str(), str.length(), &wstr[0], wstr.capacity())); 57 | 58 | // 接着转换到本地编码 59 | 60 | required_buffer_size = WideCharToMultiByte(CP_ACP, 0, &wstr[0], wstr.size(), NULL, 0, NULL, NULL); 61 | std::vector outstr; 62 | outstr.resize(required_buffer_size); 63 | 64 | int converted_size = WideCharToMultiByte(CP_ACP, 0, wstr.data(), wstr.size(), &outstr[0], required_buffer_size, NULL, NULL); 65 | outstr.resize(converted_size); 66 | 67 | return std::string(outstr.data(),outstr.size()); 68 | #else 69 | return str; 70 | #endif 71 | } 72 | 73 | // convert to utf8 from console input aka native encoding 74 | // for linux , it does nothing (linux console always use utf8) 75 | // for windows, it convert from CP_ACP 76 | inline std::string local_encode_to_utf8(const std::string & str) 77 | { 78 | #if defined(_WIN32) || defined(_WIN64) 79 | 80 | std::vector wstr; 81 | 82 | int required_buffer_size = MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), NULL, 0); 83 | wstr.resize(required_buffer_size); 84 | 85 | wstr.resize(MultiByteToWideChar(CP_ACP, 0, str.c_str(), str.length(), &wstr[0], wstr.capacity())); 86 | 87 | // 接着转换到UTF8 88 | required_buffer_size = WideCharToMultiByte(CP_UTF8, 0, &wstr[0], wstr.size(), NULL, 0, NULL, NULL); 89 | std::vector outstr; 90 | outstr.resize(required_buffer_size); 91 | 92 | int converted_size = WideCharToMultiByte(CP_UTF8, 0, wstr.data(), wstr.size(), &outstr[0], required_buffer_size, NULL, NULL); 93 | outstr.resize(converted_size); 94 | 95 | return std::string(outstr.data(),outstr.size()); 96 | #else 97 | return str; 98 | #endif 99 | } 100 | 101 | // VC 的 "字符串" 是 本地编码的,如果文件是 UTF8 BOM 的话. 102 | // 但是 MinGW 的 "字符串" 是 utf8 的 103 | // linux 下的编译器也全部是 utf8 的 104 | // 但是windows控制台输出的时候,要求的是本地编码 105 | // 而 linux 的控制台则要求的是 utf8 编码 106 | // 于是,就需要把 "字符串" 给确定的转换为本地编码 107 | // 这个代码就是干这个活用的 108 | //#if defined(_MSC_VER) || ( !defined(_WIN32) || !defined(_WIN64) ) 109 | //#define literal_to_localstr(x) std::string(x) 110 | //#else 111 | static inline std::string literal_to_localstr(const char* str) 112 | { 113 | //#ifdef _MSC_VER 114 | //#error "vc no use " 115 | //#endif 116 | return utf8_to_local_encode(str); 117 | } 118 | //#endif 119 | -------------------------------------------------------------------------------- /avboost/include/boost/timedcall.hpp: -------------------------------------------------------------------------------- 1 |  2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | namespace boost { 12 | namespace detail { 13 | 14 | template 15 | class base_delayedcall_op{ 16 | public: 17 | typedef void result_type; 18 | 19 | base_delayedcall_op(boost::asio::io_service &_io_service, int timeunitcount, Handler handler) 20 | : io_service(_io_service) 21 | , timer( new boost::asio::deadline_timer(io_service)) 22 | , m_handler(handler) 23 | { 24 | timer->expires_from_now(timeunit(timeunitcount)); 25 | timer->async_wait(*this); 26 | } 27 | 28 | void operator()(const boost::system::error_code& error) 29 | { 30 | io_service.post(m_handler); 31 | } 32 | 33 | private: 34 | boost::asio::io_service &io_service; 35 | boost::shared_ptr timer; 36 | 37 | Handler m_handler; 38 | }; 39 | 40 | 41 | template 42 | base_delayedcall_op 43 | make_delayedcallsec_op(boost::asio::io_service &_io_service, int timeunitcount, Handler handler) 44 | { 45 | return base_delayedcall_op(_io_service, timeunitcount, handler); 46 | } 47 | 48 | template 49 | base_delayedcall_op 50 | make_delayedcallms_op(boost::asio::io_service &_io_service, int timeunitcount, Handler handler) 51 | { 52 | return base_delayedcall_op(_io_service, timeunitcount, handler); 53 | } 54 | 55 | template 56 | base_delayedcall_op 57 | make_delayedcallus_op(boost::asio::io_service &_io_service, int timeunitcount, Handler handler) 58 | { 59 | return base_delayedcall_op(_io_service, timeunitcount, handler); 60 | } 61 | 62 | 63 | } // namespace detail 64 | 65 | template 66 | void delayedcallsec(boost::asio::io_service &_io_service, int timeunitcount, Handler handler) 67 | { 68 | detail::make_delayedcallsec_op(_io_service, timeunitcount, handler); 69 | } 70 | 71 | template 72 | void delayedcallms(boost::asio::io_service &_io_service, int timeunitcount, Handler handler) 73 | { 74 | detail::make_delayedcallms_op(_io_service, timeunitcount, handler); 75 | } 76 | 77 | template 78 | void delayedcallus(boost::asio::io_service &_io_service, int timeunitcount, Handler handler) 79 | { 80 | detail::make_delayedcallus_op(_io_service, timeunitcount, handler); 81 | } 82 | 83 | } // namespace boost 84 | -------------------------------------------------------------------------------- /avboost/include/boost/urlencode.hpp: -------------------------------------------------------------------------------- 1 |  2 | 3 | /* 4 | * Copyright (C) 2013 微蔡 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | */ 20 | 21 | #pragma once 22 | 23 | namespace boost{ 24 | namespace iterators{ 25 | 26 | template 27 | struct url_encode_iterator 28 | { 29 | 30 | BaseIterator m_baseposition; 31 | 32 | // 存放 %32 这样的 url 编码. 33 | typename BaseIterator::value_type cur_char_buf[3]; 34 | std::size_t cur_char_pos; 35 | 36 | private: 37 | /* Converts an integer value to its hex character*/ 38 | static char to_hex(char code) 39 | { 40 | static char hex[] = "0123456789ABCDEF"; 41 | return hex[code & 15]; 42 | } 43 | 44 | template 45 | static bool need_encode(const CharTtpe c) 46 | { 47 | return !(isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~'); 48 | } 49 | 50 | bool need_encode() const 51 | { 52 | reference c = *m_baseposition; 53 | return need_encode(c); 54 | } 55 | 56 | void fill_current() 57 | { 58 | cur_char_pos = 0; 59 | std::fill_n(cur_char_buf, sizeof cur_char_buf, 0); 60 | 61 | //判断是否需要编码. 62 | if(need_encode()) 63 | { 64 | typename BaseIterator::reference c = *m_baseposition; 65 | // 将编码后的内容放到这里. 66 | cur_char_buf[0] = '%'; 67 | cur_char_buf[1] = to_hex(c >> 4); 68 | cur_char_buf[2] = to_hex(c & 15); 69 | } 70 | } 71 | 72 | void base_inc() 73 | { 74 | ++m_baseposition; 75 | 76 | fill_current(); 77 | } 78 | 79 | void inc() 80 | { 81 | // 移动指针到下一个字母. 82 | if(need_encode()) 83 | { 84 | cur_char_pos ++; 85 | 86 | if(cur_char_pos > 2 || cur_char_buf[cur_char_pos] == '\0') 87 | { 88 | // 读到头了, 移动下一个 m_baseposition 89 | base_inc(); 90 | } 91 | } 92 | else 93 | { 94 | base_inc(); 95 | } 96 | } 97 | public: 98 | typedef typename BaseIterator::iterator_category iterator_category; 99 | typedef typename BaseIterator::value_type value_type; 100 | typedef typename BaseIterator::difference_type difference_type; 101 | typedef typename BaseIterator::pointer pointer; 102 | typedef typename BaseIterator::reference reference; 103 | public: 104 | 105 | url_encode_iterator(BaseIterator base_iter) 106 | : cur_char_pos(0), m_baseposition(base_iter) 107 | { 108 | fill_current(); 109 | } 110 | 111 | void operator ++() 112 | { 113 | inc(); 114 | } 115 | 116 | void operator ++(int) 117 | { 118 | inc(); 119 | } 120 | 121 | reference operator* () const 122 | { 123 | // 取出 当前字符. 124 | if(need_encode()) 125 | return cur_char_buf[cur_char_pos]; 126 | 127 | return * m_baseposition; 128 | } 129 | 130 | bool operator == (const url_encode_iterator & rhs) const 131 | { 132 | return m_baseposition == rhs.m_baseposition && cur_char_pos == rhs.cur_char_pos; 133 | } 134 | 135 | bool operator != (const url_encode_iterator & rhs) const 136 | { 137 | return m_baseposition != rhs.m_baseposition || cur_char_pos != rhs.cur_char_pos; 138 | } 139 | private: 140 | struct need_encode_func 141 | { 142 | template 143 | bool operator()(const CharType c) 144 | { 145 | return need_encode(c); 146 | } 147 | }; 148 | public: 149 | difference_type operator - (const url_encode_iterator & rhs) const 150 | { 151 | // 遍历到底, 然后计算有多少 need_encode , need_encode 的数量 * 2 + 字符串长度即可. 152 | return (m_baseposition - rhs.m_baseposition) 153 | + 2 * std::count_if(rhs.m_baseposition, m_baseposition , need_encode_func()); 154 | } 155 | }; 156 | 157 | } // namespace iterators 158 | /* 159 | static inline std::string url_encode(std::string str) 160 | { 161 | return std::string(iterators::url_encode_iterator(str.begin()), 162 | iterators::url_encode_iterator(str.end())); 163 | } 164 | */ 165 | 166 | } // namespace boost 167 | // kate: indent-mode cstyle; indent-width 4; replace-tabs off; tab-width 4; 168 | -------------------------------------------------------------------------------- /libtianya/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | find_package(Threads) 3 | find_package(Boost REQUIRED COMPONENTS regex thread system locale context coroutine date_time) 4 | 5 | include_directories(${OPENSSL_INCLUDE_DIR}) 6 | link_libraries(${OPENSSL_LIBRARIES}) 7 | link_directories(${Boost_LIBRARY_DIR}) 8 | 9 | include_directories(include) 10 | 11 | add_library(libtianya STATIC src/tianya_list.cpp include/util.hpp include/tianya_context.hpp include/tianya_list.hpp) 12 | -------------------------------------------------------------------------------- /libtianya/include/tianya_list.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2014 Jack. 3 | // 4 | // Author: jack 5 | // Email: jack.wgm@gmail.com 6 | // 7 | 8 | #pragma once 9 | 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include "util.hpp" 20 | 21 | using boost::asio::ip::tcp; 22 | 23 | struct list_info 24 | { 25 | std::wstring title; 26 | std::string post_url; 27 | std::wstring author; 28 | int hits; 29 | int replys; 30 | std::wstring post_time; 31 | }; 32 | 33 | class tianya_list : public boost::noncopyable 34 | { 35 | public: 36 | tianya_list(boost::asio::io_service& io) 37 | : m_io_service(io) 38 | , m_socket(io) 39 | , m_resolver(io) 40 | , m_abort(false) 41 | {} 42 | 43 | public: 44 | void start(const std::string& post_url) 45 | { 46 | m_post_url = post_url; 47 | m_state = state_unkown; 48 | url_info ui = parser_url(m_post_url); 49 | std::ostringstream port_string; 50 | port_string.imbue(std::locale("C")); 51 | port_string << ui.port; 52 | tcp::resolver::query query(ui.domain, port_string.str()); 53 | m_resolver.async_resolve(query, 54 | [this, ui](const boost::system::error_code& error, tcp::resolver::iterator endpoint_iterator) 55 | { 56 | if (!error) 57 | { 58 | if (m_socket.is_open()) 59 | { 60 | boost::system::error_code ignore_ec; 61 | m_socket.close(ignore_ec); 62 | } 63 | boost::asio::async_connect(m_socket, endpoint_iterator, 64 | [this, ui](const boost::system::error_code& error, tcp::resolver::iterator endpoint_iterator) 65 | { 66 | if (!error) 67 | { 68 | boost::asio::spawn(m_io_service, 69 | [this, ui](boost::asio::yield_context yield) 70 | { 71 | process_handle(yield, ui); 72 | }, [](std::exception_ptr){}); 73 | } 74 | }); 75 | } 76 | }); 77 | } 78 | 79 | void stop() 80 | { 81 | m_abort = true; 82 | boost::system::error_code ignore_ec; 83 | m_socket.close(ignore_ec); 84 | } 85 | 86 | template 87 | void connect_hit_item_fetched(T&& t) 88 | { 89 | m_sig_hit_item_fetched.connect(t); 90 | } 91 | 92 | // 存文件. 93 | void serialize_to_file(std::string name) 94 | { 95 | std::unique_ptr fp(std::fopen(name.c_str(), "w+b"), &std::fclose); 96 | 97 | if (!fp) 98 | return; 99 | 100 | for (auto& item : m_hits) 101 | { 102 | const list_info& data = item.second; 103 | const int tabstop = 4; 104 | std::size_t tab = 0; 105 | 106 | std::wstring buffer; 107 | std::string gbk; 108 | 109 | gbk = wide_ansi(data.title, "GBK"); 110 | tab = 30 - (gbk.size() / tabstop); 111 | buffer = data.title; 112 | for (int i = 0; i < tab; i++) 113 | buffer += L"\t"; 114 | 115 | gbk = wide_ansi(data.author, "GBK"); 116 | tab = 8 - (gbk.size() / tabstop); 117 | buffer += data.author; 118 | for (int i = 0; i < tab; i++) 119 | buffer += L"\t"; 120 | 121 | std::string tmp = std::to_string(data.hits); 122 | tab = 8 - (tmp.size() / tabstop); 123 | buffer += ansi_wide(tmp); 124 | for (int i = 0; i < tab; i++) 125 | buffer += L"\t"; 126 | 127 | tmp = std::to_string(data.replys); 128 | tab = 8 - (tmp.size() / tabstop); 129 | buffer += ansi_wide(tmp); 130 | for (int i = 0; i < tab; i++) 131 | buffer += L"\t"; 132 | 133 | buffer += data.post_time; 134 | tab = 8 - (data.post_time.size() / tabstop); 135 | for (int i = 0; i < tab; i++) 136 | buffer += L"\t"; 137 | 138 | buffer += ansi_wide(data.post_url); 139 | buffer += L"\n"; 140 | 141 | std::fputs(wide_utf8(buffer).c_str(), fp.get()); 142 | } 143 | } 144 | 145 | protected: 146 | 147 | void process_handle(boost::asio::yield_context& yield, const url_info& ui); 148 | 149 | private: 150 | boost::asio::io_context& m_io_service; 151 | tcp::socket m_socket; 152 | tcp::resolver m_resolver; 153 | boost::asio::streambuf m_request; 154 | boost::asio::streambuf m_response; 155 | typedef std::multimap ordered_info; 156 | ordered_info m_hits; 157 | ordered_info m_replys; 158 | std::string m_post_url; 159 | std::string m_next_page_url; 160 | enum { 161 | state_unkown, 162 | state_found, 163 | state_skip1, 164 | state_skip2, 165 | state_target, 166 | state_name, 167 | state_skip4, 168 | state_skip5, 169 | state_author, 170 | state_hits, 171 | state_replys, 172 | state_time 173 | } m_state; 174 | list_info m_info; 175 | boost::signals2::signal m_sig_hit_item_fetched; 176 | bool m_abort; 177 | }; 178 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 2 | set(CMAKE_AUTOMOC ON) 3 | 4 | cmake_policy(SET CMP0020 NEW) 5 | 6 | add_subdirectory(mime/) 7 | add_subdirectory(smtpclient/) 8 | 9 | configure_file(tianya.rc.in ${CMAKE_CURRENT_BINARY_DIR}/tianya.rc) 10 | 11 | file(GLOB SRCS model/*.cpp *.cpp *.h*) 12 | file(GLOB UIS *.ui) 13 | 14 | qt_add_executable(tianya ${UIS} ${SRCS} tianya.qrc dpi.manifest ${CMAKE_CURRENT_BINARY_DIR}/tianya.rc) 15 | 16 | target_include_directories(tianya PUBLIC ${Boost_INCLUDE_DIRS}) 17 | 18 | target_link_libraries(tianya PUBLIC libtianya mailmime smtpclient) 19 | 20 | target_link_libraries(tianya PUBLIC Qt6::Widgets) 21 | 22 | set_target_properties(tianya PROPERTIES 23 | WIN32_EXECUTABLE ON 24 | MACOSX_BUNDLE ON 25 | ) 26 | 27 | target_link_libraries(tianya PUBLIC ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}) 28 | 29 | if(MSVC) 30 | set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFESTINPUT:${CMAKE_CURRENT_SOURCE_DIR}/dpi.manifest") 31 | endif() 32 | 33 | install(TARGETS tianya RUNTIME DESTINATION bin) 34 | 35 | install(PROGRAMS tianya-radar.desktop DESTINATION share/applications) 36 | install(FILES tianya.svg DESTINATION share/icons) 37 | 38 | -------------------------------------------------------------------------------- /src/dpi.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | true 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/kindlesettingdialog.cpp: -------------------------------------------------------------------------------- 1 | #include "kindlesettingdialog.hpp" 2 | 3 | KindleSettingDialog::KindleSettingDialog(QWidget *parent) 4 | : QDialog(parent) 5 | { 6 | ui.setupUi(this); 7 | } 8 | 9 | KindleSettingDialog::~KindleSettingDialog() 10 | { 11 | } 12 | 13 | void KindleSettingDialog::changeEvent(QEvent *e) 14 | { 15 | QDialog::changeEvent(e); 16 | switch (e->type()) 17 | { 18 | case QEvent::LanguageChange: 19 | ui.retranslateUi(this); 20 | break; 21 | default: 22 | break; 23 | } 24 | } 25 | 26 | QString KindleSettingDialog::get_kindlemail() 27 | { 28 | return ui.kindle_mail->displayText(); 29 | } 30 | 31 | void KindleSettingDialog::set_kindlemail(QString t) 32 | { 33 | ui.kindle_mail->setText(t); 34 | } 35 | 36 | QString KindleSettingDialog::get_usermail() 37 | { 38 | return ui.sendmail->displayText(); 39 | } 40 | 41 | void KindleSettingDialog::set_usermail(QString t) 42 | { 43 | ui.sendmail->setText(t); 44 | } 45 | 46 | QString KindleSettingDialog::get_usermail_passwd() 47 | { 48 | return ui.sendmail_pwd->text(); 49 | } 50 | 51 | void KindleSettingDialog::set_usermail_passwd(QString t) 52 | { 53 | ui.sendmail_pwd->setText(t); 54 | } 55 | -------------------------------------------------------------------------------- /src/kindlesettingdialog.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "ui_kindlesettingdialog.h" 4 | 5 | class KindleSettingDialog : public QDialog 6 | { 7 | Q_OBJECT 8 | 9 | Q_PROPERTY(QString kindlemail READ get_kindlemail WRITE set_kindlemail); 10 | Q_PROPERTY(QString usermail READ get_usermail WRITE set_usermail); 11 | Q_PROPERTY(QString usermail_passwd READ get_usermail_passwd WRITE set_usermail_passwd); 12 | 13 | public: 14 | explicit KindleSettingDialog(QWidget *parent = 0); 15 | 16 | virtual ~KindleSettingDialog(); 17 | 18 | protected: 19 | void changeEvent(QEvent *e); 20 | 21 | public: 22 | QString get_kindlemail(); 23 | void set_kindlemail(QString); 24 | 25 | QString get_usermail(); 26 | void set_usermail(QString); 27 | 28 | QString get_usermail_passwd(); 29 | void set_usermail_passwd(QString); 30 | 31 | private: 32 | Ui::KindleSettingDialog ui; 33 | }; 34 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include 3 | #include 4 | 5 | #include 6 | 7 | #include "tianyawindow.hpp" 8 | #include "syncobj.hpp" 9 | 10 | class AsioQApplication : public QApplication 11 | { 12 | public: 13 | AsioQApplication(int& argc, char* argv[]) 14 | : QApplication(argc, argv) 15 | { 16 | m_asio_thread = std::thread([this]() 17 | { 18 | m_work.reset(new boost::asio::io_service::work(m_asio)); 19 | #ifdef _WIN32 20 | auto ret = ::SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_IDLE); 21 | BOOST_ASSERT(ret); 22 | #endif 23 | m_asio.run(); 24 | }); 25 | 26 | connect(this, &QApplication::aboutToQuit, this, [this]() 27 | { 28 | m_asio.post([this](){m_work.reset();}); 29 | }); 30 | 31 | struct sched_param param{0}; 32 | 33 | pthread_setschedparam(m_asio_thread.native_handle(), SCHED_IDLE, ¶m); 34 | } 35 | 36 | boost::asio::io_service& get_io_service(){return m_asio;} 37 | 38 | ~AsioQApplication() 39 | { 40 | m_asio_thread.join(); 41 | } 42 | 43 | private: 44 | std::thread m_asio_thread; 45 | boost::asio::io_service m_asio; 46 | std::unique_ptr m_work; 47 | }; 48 | 49 | static SyncObjec * _syncobj; 50 | 51 | #ifdef _WIN32 52 | #include "resource.h" 53 | 54 | extern QPixmap qt_pixmapFromWinHICON(HICON); 55 | 56 | static QIcon load_win32_icon() 57 | { 58 | QIcon ico; 59 | HICON hicon = (HICON)::LoadImage(GetModuleHandle(nullptr), MAKEINTRESOURCE(IDI_TIANYA_ICON), 60 | IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_LOADTRANSPARENT); 61 | ico = QIcon(qt_pixmapFromWinHICON(hicon)); 62 | ::DestroyIcon(hicon); 63 | return ico; 64 | } 65 | #endif 66 | 67 | int main(int argc, char *argv[]) 68 | { 69 | std::locale::global(std::locale("")); 70 | // work arround VC 71 | SyncObjec syncobj; 72 | _syncobj = &syncobj; 73 | AsioQApplication app(argc, argv); 74 | app.setOrganizationName("avplayer"); 75 | app.setOrganizationDomain("avplayer.org"); 76 | app.setApplicationName("tianyaradar"); 77 | #ifdef _WIN32 78 | app.setWindowIcon(load_win32_icon()); 79 | #else 80 | app.setWindowIcon(QIcon(":/icon/tianya.svg")); 81 | #endif 82 | 83 | // 创建 主窗口 84 | TianyaWindow mainwindow(app.get_io_service()); 85 | 86 | mainwindow.showMaximized(); 87 | 88 | return app.exec(); 89 | } 90 | 91 | void post_on_gui_thread(std::function func) 92 | { 93 | _syncobj->do_post(func); 94 | } 95 | 96 | 97 | #ifdef _WIN32 98 | 99 | #ifdef STATIC_QT5 100 | #include 101 | #include 102 | 103 | Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin); 104 | 105 | Q_IMPORT_PLUGIN(QICOPlugin); 106 | 107 | #ifdef _DEBUG 108 | #pragma comment(lib, "Qt5PlatformSupportd.lib") 109 | #pragma comment(lib, "qwindowsd.lib") 110 | #pragma comment(lib, "qicod.lib") 111 | #else 112 | #pragma comment(lib, "Qt5PlatformSupport.lib") 113 | #pragma comment(lib, "qwindows.lib") 114 | #pragma comment(lib, "qico.lib") 115 | #endif 116 | 117 | #pragma comment(lib, "opengl32.lib") 118 | #pragma comment(lib, "Imm32.lib") 119 | #pragma comment(lib, "winmm.lib") 120 | 121 | #endif 122 | #endif 123 | -------------------------------------------------------------------------------- /src/mime/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 2 | set(CMAKE_AUTOMOC ON) 3 | 4 | file(GLOB SRCS src/*.cpp include/*.h*) 5 | 6 | add_library(mailmime STATIC ${SRCS}) 7 | 8 | target_include_directories(mailmime PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include) 9 | 10 | target_link_libraries(mailmime PUBLIC Qt6::Widgets Qt6::Network) 11 | -------------------------------------------------------------------------------- /src/mime/include/emailaddress.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012 - Tőkés Attila 3 | 4 | This file is part of SmtpClient for Qt. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | See the LICENSE file for more details. 17 | */ 18 | 19 | #ifndef EMAILADDRESS_H 20 | #define EMAILADDRESS_H 21 | 22 | #include "smtpmime_global.h" 23 | #include 24 | 25 | class SMTP_MIME_EXPORT EmailAddress 26 | { 27 | public: 28 | 29 | /* [1] Constructors and Destructors */ 30 | 31 | EmailAddress(const QString & address = "", const QString & name = ""); 32 | 33 | /* [1] --- */ 34 | 35 | 36 | /* [2] Getters and Setters */ 37 | 38 | QString getAddress() const; 39 | QString getName() const; 40 | 41 | /* [2] --- */ 42 | 43 | 44 | private: 45 | 46 | /* [3] Private members */ 47 | 48 | QString address; 49 | QString name; 50 | 51 | /* [3] --- */ 52 | }; 53 | 54 | #endif // EMAILADDRESS_H 55 | -------------------------------------------------------------------------------- /src/mime/include/mimeattachment.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012 - Tőkés Attila 3 | 4 | This file is part of SmtpClient for Qt. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | See the LICENSE file for more details. 17 | */ 18 | 19 | #ifndef MIMEATTACHMENT_H 20 | #define MIMEATTACHMENT_H 21 | 22 | 23 | #include "smtpmime_global.h" 24 | #include "mimepart.h" 25 | #include "mimefile.h" 26 | 27 | class SMTP_MIME_EXPORT MimeAttachment : public MimeFile 28 | { 29 | public: 30 | 31 | /* [1] Constructors and Destructors */ 32 | 33 | MimeAttachment(QFile* file); 34 | MimeAttachment(const QByteArray& stream, const QString& fileName); 35 | ~MimeAttachment(); 36 | 37 | /* [1] --- */ 38 | 39 | protected: 40 | 41 | /* [2] Protected methods */ 42 | /* [2] --- */ 43 | }; 44 | 45 | #endif // MIMEATTACHMENT_H 46 | -------------------------------------------------------------------------------- /src/mime/include/mimebase64encoder.h: -------------------------------------------------------------------------------- 1 | #ifndef MIMEBASE64ENCODER_H 2 | #define MIMEBASE64ENCODER_H 3 | 4 | #include "mimecontentencoder.h" 5 | 6 | class MimeBase64Encoder : public MimeContentEncoder 7 | { 8 | public: 9 | MimeBase64Encoder(); 10 | 11 | QByteArray encode(const QByteArray &data); 12 | }; 13 | 14 | #endif // MIMEBASE64ENCODER_H 15 | -------------------------------------------------------------------------------- /src/mime/include/mimebase64formatter.h: -------------------------------------------------------------------------------- 1 | #ifndef MIMEBASE64FORMATTER_H 2 | #define MIMEBASE64FORMATTER_H 3 | 4 | #include "mimecontentformatter.h" 5 | 6 | class MimeBase64Formatter : public MimeContentFormatter 7 | { 8 | public: 9 | MimeBase64Formatter(QIODevice*); 10 | 11 | protected: 12 | virtual qint64 writeData(const char *data, qint64 len); 13 | }; 14 | 15 | #endif // MIMEBASE64FORMATTER_H 16 | -------------------------------------------------------------------------------- /src/mime/include/mimebytearrayattachment.h: -------------------------------------------------------------------------------- 1 | #ifndef MIMEBYTEARRAYATTACHMENT_H 2 | #define MIMEBYTEARRAYATTACHMENT_H 3 | 4 | #include "smtpmime_global.h" 5 | #include "mimepart.h" 6 | 7 | class SMTP_MIME_EXPORT MimeByteArrayAttachment : public MimePart 8 | { 9 | public: 10 | /* [1] Constructors and Destructors */ 11 | 12 | MimeByteArrayAttachment(const QString& name, const QByteArray &content); 13 | ~MimeByteArrayAttachment(); 14 | 15 | /* [1] --- */ 16 | 17 | 18 | }; 19 | 20 | #endif // MIMEBYTEARRAYATTACHMENT_H 21 | -------------------------------------------------------------------------------- /src/mime/include/mimecontentencoder.h: -------------------------------------------------------------------------------- 1 | #ifndef MIMEENCODER_H 2 | #define MIMEENCODER_H 3 | 4 | #include 5 | #include 6 | 7 | class MimeContentEncoder : public QObject 8 | { 9 | public: 10 | virtual QByteArray encode(const QByteArray &data) =0; 11 | 12 | protected: 13 | MimeContentEncoder(); 14 | }; 15 | 16 | #endif // MIMEENCODER_H 17 | -------------------------------------------------------------------------------- /src/mime/include/mimecontentformatter.h: -------------------------------------------------------------------------------- 1 | #ifndef MIMECONTENTFORMATTER_H 2 | #define MIMECONTENTFORMATTER_H 3 | 4 | #include 5 | #include 6 | 7 | class MimeContentFormatter : public QIODevice 8 | { 9 | Q_OBJECT 10 | public: 11 | MimeContentFormatter(QIODevice *device, int lineLength = 76); 12 | 13 | int getLineLength() const; 14 | void setLineLength(int l); 15 | 16 | protected: 17 | qint64 readData(char *data, qint64 maxlen); 18 | qint64 writeData(const char *data, qint64 len) = 0; 19 | 20 | QIODevice *output; 21 | int lineLength; 22 | }; 23 | 24 | #endif // MIMECONTENTFORMATTER_H 25 | -------------------------------------------------------------------------------- /src/mime/include/mimefile.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012 - Tőkés Attila 3 | 4 | This file is part of SmtpClient for Qt. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | See the LICENSE file for more details. 17 | */ 18 | 19 | #ifndef MIMEFILE_H 20 | #define MIMEFILE_H 21 | 22 | #include "mimepart.h" 23 | #include "smtpmime_global.h" 24 | 25 | class QFile; 26 | 27 | class SMTP_MIME_EXPORT MimeFile : public MimePart 28 | { 29 | public: 30 | 31 | /* [1] Constructors and Destructors */ 32 | 33 | MimeFile(QFile *f); 34 | MimeFile(const QByteArray& stream, const QString& fileName); 35 | 36 | ~MimeFile(); 37 | 38 | /* [1] --- */ 39 | 40 | 41 | /* [2] Getters and Setters */ 42 | 43 | /* [2] --- */ 44 | 45 | protected: 46 | 47 | /* [3] Protected members */ 48 | 49 | QFile* file; 50 | 51 | /* [3] --- */ 52 | 53 | 54 | /* [4] Protected methods */ 55 | 56 | void writeContent(QIODevice &device) const; 57 | 58 | 59 | /* [4] --- */ 60 | 61 | }; 62 | 63 | #endif // MIMEFILE_H 64 | -------------------------------------------------------------------------------- /src/mime/include/mimehtml.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012 - Tőkés Attila 3 | 4 | This file is part of SmtpClient for Qt. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | See the LICENSE file for more details. 17 | */ 18 | 19 | #ifndef MIMEHTML_H 20 | #define MIMEHTML_H 21 | 22 | #include "smtpmime_global.h" 23 | #include "mimetext.h" 24 | 25 | class SMTP_MIME_EXPORT MimeHtml : public MimeText 26 | { 27 | public: 28 | 29 | /* [1] Constructors and Destructors */ 30 | 31 | MimeHtml(const QString &html = ""); 32 | ~MimeHtml(); 33 | 34 | /* [1] --- */ 35 | 36 | 37 | /* [2] Getters and Setters */ 38 | 39 | void setHtml(const QString & html); 40 | 41 | QString getHtml() const; 42 | 43 | /* [2] --- */ 44 | 45 | protected: 46 | 47 | /* [3] Protected members */ 48 | 49 | /* [3] --- */ 50 | 51 | 52 | /* [4] Protected methods */ 53 | 54 | /* [4] --- */ 55 | }; 56 | 57 | #endif // MIMEHTML_H 58 | -------------------------------------------------------------------------------- /src/mime/include/mimeinlinefile.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012 - Tőkés Attila 3 | 4 | This file is part of SmtpClient for Qt. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | See the LICENSE file for more details. 17 | */ 18 | 19 | #ifndef MIMEINLINEFILE_H 20 | #define MIMEINLINEFILE_H 21 | 22 | #include "smtpmime_global.h" 23 | #include "mimefile.h" 24 | 25 | class SMTP_MIME_EXPORT MimeInlineFile : public MimeFile 26 | { 27 | public: 28 | 29 | /* [1] Constructors and Destructors */ 30 | 31 | MimeInlineFile(QFile *f); 32 | ~MimeInlineFile(); 33 | 34 | /* [1] --- */ 35 | 36 | 37 | /* [2] Getters and Setters */ 38 | 39 | /* [2] --- */ 40 | 41 | protected: 42 | 43 | /* [3] Protected members */ 44 | 45 | /* [3] --- */ 46 | 47 | 48 | /* [4] Protected methods */ 49 | 50 | /* [4] --- */ 51 | }; 52 | 53 | #endif // MIMEINLINEFILE_H 54 | -------------------------------------------------------------------------------- /src/mime/include/mimemessage.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012 - Tőkés Attila 3 | 4 | This file is part of SmtpClient for Qt. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | See the LICENSE file for more details. 17 | */ 18 | 19 | #ifndef MIMEMESSAGE_H 20 | #define MIMEMESSAGE_H 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include "smtpmime_global.h" 27 | #include "mimepart.h" 28 | #include "emailaddress.h" 29 | 30 | class SMTP_MIME_EXPORT MimeMessage : public QObject 31 | { 32 | public: 33 | 34 | enum RecipientType { 35 | To, // primary 36 | Cc, // carbon copy 37 | Bcc // blind carbon copy 38 | }; 39 | 40 | /* [1] Constructors and Destructors */ 41 | 42 | MimeMessage(bool createAutoMimeContent = true); 43 | ~MimeMessage(); 44 | 45 | /* [1] --- */ 46 | 47 | 48 | /* [2] Getters and Setters */ 49 | 50 | void setSender(const EmailAddress &sndr); 51 | void setReplyTo(const EmailAddress &repto); 52 | void addRecipient(const EmailAddress &rcpt, RecipientType type = To); 53 | void addTo(const EmailAddress &rcpt); 54 | void addCc(const EmailAddress &rcpt); 55 | void addBcc(const EmailAddress &rcpt); 56 | void addCustomHeader(const QString &hdr); 57 | void setSubject(const QString &subject); 58 | void addPart(MimePart* part); 59 | void addPart(MimePart* part, const bool takeOwnership); 60 | 61 | void setHeaderEncoding(MimePart::Encoding); 62 | 63 | EmailAddress getSender() const; 64 | EmailAddress getReplyTo() const; 65 | const QList &getRecipients(RecipientType type = To) const; 66 | QString getSubject() const; 67 | const QStringList &getCustomHeaders() const; 68 | const QList & getParts() const; 69 | 70 | MimePart& getContent(); 71 | void setContent(MimePart *content); 72 | /* [2] --- */ 73 | 74 | 75 | /* [3] Public methods */ 76 | 77 | virtual QString toString() const; 78 | void writeToDevice(QIODevice &device) const; 79 | 80 | /* [3] --- */ 81 | 82 | protected: 83 | 84 | /* [4] Protected members */ 85 | 86 | EmailAddress sender; 87 | EmailAddress replyTo; 88 | QList recipientsTo, recipientsCc, recipientsBcc; 89 | QString subject; 90 | QStringList customHeaders; 91 | MimePart *content; 92 | bool mimeContentAutoCreated; 93 | 94 | MimePart::Encoding hEncoding; 95 | 96 | static QByteArray format(const QString &text, MimePart::Encoding encoding); 97 | static QByteArray formatAddress(const EmailAddress &address, MimePart::Encoding encoding); 98 | 99 | /* [4] --- */ 100 | 101 | 102 | }; 103 | 104 | #endif // MIMEMESSAGE_H 105 | -------------------------------------------------------------------------------- /src/mime/include/mimemultipart.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012 - Tőkés Attila 3 | 4 | This file is part of SmtpClient for Qt. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | See the LICENSE file for more details. 17 | */ 18 | 19 | #ifndef MIMEMULTIPART_H 20 | #define MIMEMULTIPART_H 21 | 22 | #include 23 | #include "smtpmime_global.h" 24 | #include "mimepart.h" 25 | 26 | class SMTP_MIME_EXPORT MimeMultiPart : public MimePart 27 | { 28 | public: 29 | 30 | /* [0] Enums */ 31 | enum MultiPartType { 32 | Mixed = 0, // RFC 2046, section 5.1.3 33 | Digest = 1, // RFC 2046, section 5.1.5 34 | Alternative = 2, // RFC 2046, section 5.1.4 35 | Related = 3, // RFC 2387 36 | Report = 4, // RFC 6522 37 | Signed = 5, // RFC 1847, section 2.1 38 | Encrypted = 6 // RFC 1847, section 2.2 39 | }; 40 | 41 | /* [0] --- */ 42 | 43 | /* [1] Constructors and Destructors */ 44 | MimeMultiPart(const MultiPartType type = Related); 45 | 46 | ~MimeMultiPart(); 47 | 48 | /* [1] --- */ 49 | 50 | /* [2] Getters and Setters */ 51 | 52 | void setMimeType(const MultiPartType type); 53 | MultiPartType getMimeType() const; 54 | 55 | const QList & getParts() const; 56 | 57 | /* [2] --- */ 58 | 59 | /* [3] Public methods */ 60 | 61 | void addPart(MimePart *part); 62 | 63 | void addPart(MimePart *part, const bool takeOwnership); 64 | 65 | void writeContent(QIODevice &device) const; 66 | 67 | /* [3] --- */ 68 | 69 | protected: 70 | QList< MimePart* > parts; 71 | 72 | QList< MimePart* > ownedParts; 73 | 74 | MultiPartType type; 75 | 76 | }; 77 | 78 | #endif // MIMEMULTIPART_H 79 | -------------------------------------------------------------------------------- /src/mime/include/mimepart.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012 - Tőkés Attila 3 | 4 | This file is part of SmtpClient for Qt. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | See the LICENSE file for more details. 17 | */ 18 | 19 | #ifndef MIMEPART_H 20 | #define MIMEPART_H 21 | 22 | #include "smtpmime_global.h" 23 | #include 24 | #include 25 | 26 | class QIODevice; 27 | 28 | class SMTP_MIME_EXPORT MimePart 29 | { 30 | public: 31 | 32 | /* [0] Enumerations */ 33 | enum Encoding { 34 | _7Bit, 35 | _8Bit, 36 | Base64, 37 | QuotedPrintable 38 | }; 39 | 40 | 41 | /* [0] --- */ 42 | 43 | 44 | /* [1] Constructors and Destructors */ 45 | 46 | MimePart(); 47 | virtual ~MimePart(); 48 | 49 | /* [1] --- */ 50 | 51 | 52 | /* [2] Getters and Setters */ 53 | 54 | void setContent(const QByteArray & content); 55 | QByteArray getContent() const; 56 | 57 | void setHeader(const QString & headerLines); 58 | QString getHeader() const; 59 | 60 | void addHeaderLine(const QString & line); 61 | 62 | void setContentId(const QString & cId); 63 | QString getContentId() const; 64 | 65 | void setContentName(const QString & cName); 66 | QString getContentName() const; 67 | 68 | void setContentType(const QString & cType); 69 | QString getContentType() const; 70 | 71 | void setCharset(const QString & charset); 72 | QString getCharset() const; 73 | 74 | void setEncoding(Encoding enc); 75 | Encoding getEncoding() const; 76 | 77 | void setMaxLineLength(const int length); 78 | int getMaxLineLength() const; 79 | 80 | /* [2] --- */ 81 | 82 | 83 | /* [3] Public methods */ 84 | 85 | virtual QString toString() const; 86 | void writeToDevice(QIODevice &device) const; 87 | 88 | /* [3] --- */ 89 | 90 | protected: 91 | 92 | /* [4] Protected members */ 93 | 94 | QString headerLines; 95 | QByteArray content; 96 | 97 | QString cId; 98 | QString cName; 99 | QString cType; 100 | QString cCharset; 101 | QString cBoundary; 102 | Encoding cEncoding; 103 | 104 | int maxLineLength; 105 | 106 | QString mimeString; 107 | bool prepared; 108 | 109 | /* [4] --- */ 110 | 111 | virtual void writeContent(QIODevice &device) const; 112 | void writeContent(QIODevice &device, const QByteArray &content) const; 113 | }; 114 | 115 | #endif // MIMEPART_H 116 | -------------------------------------------------------------------------------- /src/mime/include/mimeqpencoder.h: -------------------------------------------------------------------------------- 1 | #ifndef MIMEQPENCODER_H 2 | #define MIMEQPENCODER_H 3 | 4 | #include "mimecontentencoder.h" 5 | 6 | class MimeQpEncoder : public MimeContentEncoder 7 | { 8 | public: 9 | MimeQpEncoder(); 10 | 11 | QByteArray encode(const QByteArray &data); 12 | }; 13 | 14 | #endif // MIMEQPENCODER_H 15 | -------------------------------------------------------------------------------- /src/mime/include/mimeqpformatter.h: -------------------------------------------------------------------------------- 1 | #ifndef MIMEQPFORMATTER_H 2 | #define MIMEQPFORMATTER_H 3 | 4 | #include "mimecontentformatter.h" 5 | 6 | class MimeQPFormatter : public MimeContentFormatter 7 | { 8 | public: 9 | MimeQPFormatter(QIODevice*); 10 | 11 | protected: 12 | virtual qint64 writeData(const char *data, qint64 len); 13 | }; 14 | 15 | #endif // MIMEQPFORMATTER_H 16 | -------------------------------------------------------------------------------- /src/mime/include/mimetext.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012 - Tőkés Attila 3 | 4 | This file is part of SmtpClient for Qt. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | See the LICENSE file for more details. 17 | */ 18 | 19 | #ifndef MIMETEXT_H 20 | #define MIMETEXT_H 21 | 22 | #include "smtpmime_global.h" 23 | #include "mimepart.h" 24 | 25 | class SMTP_MIME_EXPORT MimeText : public MimePart 26 | { 27 | public: 28 | 29 | /* [1] Constructors and Destructors */ 30 | 31 | MimeText(const QString &text = ""); 32 | ~MimeText(); 33 | 34 | /* [1] --- */ 35 | 36 | 37 | /* [2] Getters and Setters*/ 38 | 39 | void setText(const QString & text); 40 | 41 | const QString & getText() const; 42 | 43 | /* [2] --- */ 44 | 45 | protected: 46 | 47 | /* [3] Protected members */ 48 | 49 | QString text; 50 | /* [3] --- */ 51 | 52 | 53 | /* [4] Protected methods */ 54 | 55 | void writeContent(QIODevice &device) const; 56 | 57 | /* [4] --- */ 58 | 59 | }; 60 | 61 | #endif // MIMETEXT_H 62 | -------------------------------------------------------------------------------- /src/mime/include/quotedprintable.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012 - Tőkés Attila 3 | 4 | This file is part of SmtpClient for Qt. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | See the LICENSE file for more details. 17 | */ 18 | 19 | #ifndef QUOTEDPRINTABLE_H 20 | #define QUOTEDPRINTABLE_H 21 | 22 | #include 23 | #include 24 | #include "smtpmime_global.h" 25 | 26 | namespace QuotedPrintable { 27 | SMTP_MIME_EXPORT QString encode(const QByteArray &input); 28 | SMTP_MIME_EXPORT QByteArray decode(const QString &input); 29 | } 30 | 31 | #endif // QUOTEDPRINTABLE_H 32 | -------------------------------------------------------------------------------- /src/mime/include/smtpmime_global.h: -------------------------------------------------------------------------------- 1 | #ifndef SMTPMIME_GLOBAL_H 2 | #define SMTPMIME_GLOBAL_H 3 | 4 | #ifdef SMTP_MIME_LIBRARY 5 | #define SMTP_MIME_EXPORT Q_DECL_EXPORT 6 | #else 7 | #define SMTP_MIME_EXPORT Q_DECL_IMPORT 8 | #endif 9 | 10 | #endif // SMTPMIME_GLOBAL_H 11 | -------------------------------------------------------------------------------- /src/mime/src/emailaddress.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012 - Tőkés Attila 3 | 4 | This file is part of SmtpClient for Qt. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | See the LICENSE file for more details. 17 | */ 18 | 19 | #include "emailaddress.h" 20 | 21 | /* [1] Constructors and Destructors */ 22 | 23 | EmailAddress::EmailAddress(const QString & address, const QString & name) 24 | : address(address), name(name) 25 | { 26 | } 27 | 28 | /* [1] --- */ 29 | 30 | 31 | /* [2] Getters and Setters */ 32 | 33 | 34 | QString EmailAddress::getName() const 35 | { 36 | return name; 37 | } 38 | 39 | QString EmailAddress::getAddress() const 40 | { 41 | return address; 42 | } 43 | 44 | /* [2] --- */ 45 | 46 | -------------------------------------------------------------------------------- /src/mime/src/mimeattachment.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012 - Tőkés Attila 3 | 4 | This file is part of SmtpClient for Qt. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | See the LICENSE file for more details. 17 | */ 18 | 19 | #include "mimeattachment.h" 20 | #include 21 | 22 | /* [1] Constructors and Destructors */ 23 | 24 | MimeAttachment::MimeAttachment(QFile *file) 25 | : MimeFile(file) 26 | { 27 | this->headerLines += "Content-disposition: attachment; filename=\"" + cName + "\"\r\n"; 28 | } 29 | 30 | MimeAttachment::MimeAttachment(const QByteArray& stream, const QString& fileName) 31 | : MimeFile(stream, fileName) 32 | { 33 | this->headerLines += "Content-disposition: attachment; filename=\"" + fileName + "\"\r\n"; 34 | } 35 | 36 | 37 | MimeAttachment::~MimeAttachment() 38 | { 39 | } 40 | 41 | /* [1] --- */ 42 | 43 | 44 | /* [2] Protected methods */ 45 | 46 | /* [2] --- */ 47 | -------------------------------------------------------------------------------- /src/mime/src/mimebase64encoder.cpp: -------------------------------------------------------------------------------- 1 | #include "mimebase64encoder.h" 2 | 3 | MimeBase64Encoder::MimeBase64Encoder() {} 4 | 5 | QByteArray MimeBase64Encoder::encode(const QByteArray &data) { 6 | return data.toBase64(); 7 | } 8 | -------------------------------------------------------------------------------- /src/mime/src/mimebase64formatter.cpp: -------------------------------------------------------------------------------- 1 | #include "mimebase64formatter.h" 2 | 3 | MimeBase64Formatter::MimeBase64Formatter(QIODevice *out) : 4 | MimeContentFormatter(out) {} 5 | 6 | qint64 MimeBase64Formatter::writeData(const char *data, qint64 maxLength) { 7 | int lines = (maxLength - 1) / lineLength + 1; 8 | for (int i = 1; i < lines; ++i) { 9 | output->write(data, lineLength); 10 | output->write("\r\n"); 11 | data += lineLength; 12 | } 13 | output->write(data, maxLength - (lines - 1) * lineLength); 14 | output->write("\r\n"); 15 | return maxLength; 16 | } 17 | -------------------------------------------------------------------------------- /src/mime/src/mimebytearrayattachment.cpp: -------------------------------------------------------------------------------- 1 | #include "mimebytearrayattachment.h" 2 | 3 | MimeByteArrayAttachment::MimeByteArrayAttachment(const QString& name, const QByteArray &content) : 4 | MimePart() 5 | { 6 | this->cType = "application/octet-stream"; 7 | this->cEncoding = Base64; 8 | this->cName = name, 9 | this->content = content; 10 | } 11 | 12 | MimeByteArrayAttachment::~MimeByteArrayAttachment() {} 13 | 14 | -------------------------------------------------------------------------------- /src/mime/src/mimecontentencoder.cpp: -------------------------------------------------------------------------------- 1 | #include "mimecontentencoder.h" 2 | 3 | MimeContentEncoder::MimeContentEncoder() {} 4 | -------------------------------------------------------------------------------- /src/mime/src/mimecontentformatter.cpp: -------------------------------------------------------------------------------- 1 | #include "mimecontentformatter.h" 2 | 3 | MimeContentFormatter::MimeContentFormatter(QIODevice *out, int length) : 4 | output(out), 5 | lineLength(length) 6 | { 7 | QIODevice::open(WriteOnly); 8 | } 9 | 10 | int MimeContentFormatter::getLineLength() const { 11 | return lineLength; 12 | } 13 | 14 | void MimeContentFormatter::setLineLength(int l) { 15 | lineLength = l; 16 | } 17 | 18 | qint64 MimeContentFormatter::readData(char*, qint64) { 19 | return -1; 20 | } 21 | -------------------------------------------------------------------------------- /src/mime/src/mimefile.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012 - Tőkés Attila 3 | 4 | This file is part of SmtpClient for Qt. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | See the LICENSE file for more details. 17 | */ 18 | 19 | #include "mimefile.h" 20 | #include 21 | #include 22 | #include 23 | 24 | /* [1] Constructors and Destructors */ 25 | 26 | MimeFile::MimeFile(QFile *file) 27 | { 28 | QFileInfo fileInfo(*file); 29 | QMimeType mimeType = QMimeDatabase().mimeTypeForFile(fileInfo); 30 | 31 | this->file = file; 32 | this->cType = mimeType.name(); 33 | this->cName = fileInfo.fileName(); 34 | this->cEncoding = Base64; 35 | } 36 | 37 | 38 | MimeFile::MimeFile(const QByteArray& stream, const QString& fileName) 39 | { 40 | this->cEncoding = Base64; 41 | this->cType = "application/octet-stream"; 42 | this->file = 0; 43 | this->cName = fileName; 44 | this->content = stream; 45 | } 46 | 47 | MimeFile::~MimeFile() 48 | { 49 | } 50 | 51 | /* [1] --- */ 52 | 53 | 54 | /* [2] Getters and setters */ 55 | 56 | /* [2] --- */ 57 | 58 | 59 | /* [3] Protected methods */ 60 | 61 | 62 | void MimeFile::writeContent(QIODevice &device) const { 63 | file->open(QIODevice::ReadOnly); 64 | const QByteArray &fileContent = file->readAll(); 65 | file->close(); 66 | 67 | MimePart::writeContent(device, fileContent); 68 | } 69 | 70 | /* [3] --- */ 71 | 72 | -------------------------------------------------------------------------------- /src/mime/src/mimehtml.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012 - Tőkés Attila 3 | 4 | This file is part of SmtpClient for Qt. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | See the LICENSE file for more details. 17 | */ 18 | 19 | #include "mimehtml.h" 20 | 21 | /* [1] Constructors and Destructors */ 22 | 23 | MimeHtml::MimeHtml(const QString &html) : MimeText(html) 24 | { 25 | this->cType = "text/html"; 26 | } 27 | 28 | MimeHtml::~MimeHtml() {} 29 | 30 | /* [1] --- */ 31 | 32 | 33 | /* [2] Getters and Setters */ 34 | 35 | void MimeHtml::setHtml(const QString & html) 36 | { 37 | this->text = html; 38 | } 39 | 40 | QString MimeHtml::getHtml() const 41 | { 42 | return text; 43 | } 44 | 45 | 46 | /* [2] --- */ 47 | 48 | 49 | /* [3] Protected methods */ 50 | 51 | /* [3] --- */ 52 | -------------------------------------------------------------------------------- /src/mime/src/mimeinlinefile.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012 - Tőkés Attila 3 | 4 | This file is part of SmtpClient for Qt. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | See the LICENSE file for more details. 17 | */ 18 | 19 | #include "mimeinlinefile.h" 20 | 21 | /* [1] Constructors and Destructors */ 22 | 23 | MimeInlineFile::MimeInlineFile(QFile *f) 24 | : MimeFile(f) 25 | { 26 | addHeaderLine("Content-Disposition: inline"); 27 | } 28 | 29 | MimeInlineFile::~MimeInlineFile() 30 | {} 31 | 32 | /* [1] --- */ 33 | 34 | 35 | /* [2] Getters and Setters */ 36 | 37 | /* [2] --- */ 38 | 39 | 40 | /* [3] Protected methods */ 41 | 42 | /* [3] --- */ 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /src/mime/src/mimemultipart.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012 - Tőkés Attila 3 | 4 | This file is part of SmtpClient for Qt. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | See the LICENSE file for more details. 17 | */ 18 | 19 | #include "mimemultipart.h" 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | const QString MULTI_PART_NAMES[] = { 26 | "multipart/mixed", // Mixed 27 | "multipart/digest", // Digest 28 | "multipart/alternative", // Alternative 29 | "multipart/related", // Related 30 | "multipart/report", // Report 31 | "multipart/signed", // Signed 32 | "multipart/encrypted" // Encrypted 33 | }; 34 | 35 | MimeMultiPart::MimeMultiPart(MultiPartType type) 36 | { 37 | this->type = type; 38 | this->cType = MULTI_PART_NAMES[this->type]; 39 | this->cEncoding = _8Bit; 40 | 41 | QCryptographicHash md5(QCryptographicHash::Md5); 42 | md5.addData(QByteArray().append(QRandomGenerator::global()->generate64())); 43 | cBoundary = md5.result().toHex(); 44 | } 45 | 46 | MimeMultiPart::~MimeMultiPart() { 47 | foreach (MimePart *part, ownedParts) { 48 | delete part; 49 | } 50 | } 51 | 52 | void MimeMultiPart::addPart(MimePart *part) { 53 | this->addPart(part, false); 54 | } 55 | 56 | void MimeMultiPart::addPart(MimePart *part, const bool takeOwnership) { 57 | parts.append(part); 58 | if (takeOwnership) { 59 | ownedParts.append(part); 60 | } 61 | } 62 | 63 | const QList & MimeMultiPart::getParts() const { 64 | return parts; 65 | } 66 | 67 | void MimeMultiPart::writeContent(QIODevice &device) const { 68 | QList::const_iterator it; 69 | 70 | for (it = parts.constBegin(); it != parts.constEnd(); it++) { 71 | device.write("--" ); 72 | device.write(cBoundary.toLatin1()); 73 | device.write("\r\n"); 74 | (*it)->writeToDevice(device); 75 | }; 76 | 77 | device.write("--"); 78 | device.write(cBoundary.toLatin1()); 79 | device.write("--\r\n"); 80 | } 81 | 82 | 83 | void MimeMultiPart::setMimeType(const MultiPartType type) { 84 | this->type = type; 85 | this->cType = MULTI_PART_NAMES[type]; 86 | } 87 | 88 | MimeMultiPart::MultiPartType MimeMultiPart::getMimeType() const { 89 | return type; 90 | } 91 | -------------------------------------------------------------------------------- /src/mime/src/mimeqpencoder.cpp: -------------------------------------------------------------------------------- 1 | #include "mimeqpencoder.h" 2 | #include "quotedprintable.h" 3 | 4 | MimeQpEncoder::MimeQpEncoder() {} 5 | 6 | QByteArray MimeQpEncoder::encode(const QByteArray &data) { 7 | return QuotedPrintable::encode(data).toLatin1(); 8 | } 9 | -------------------------------------------------------------------------------- /src/mime/src/mimeqpformatter.cpp: -------------------------------------------------------------------------------- 1 | #include "mimeqpformatter.h" 2 | 3 | MimeQPFormatter::MimeQPFormatter(QIODevice *output) : 4 | MimeContentFormatter(output) {} 5 | 6 | qint64 MimeQPFormatter::writeData(const char *data, qint64 maxLength) { 7 | int chars = 0; 8 | const char *start = data; 9 | for (int i = 0; i < maxLength; ++i) { 10 | chars++; 11 | if (data[i] == '\n') { 12 | output->write(start, chars); 13 | start += chars; 14 | chars = 0; 15 | } else if ((chars > lineLength - 3) && (data[i] == '=')) { 16 | output->write(start, chars - 1); 17 | output->write("=\r\n="); 18 | start += chars; 19 | chars = 0; 20 | } else if (chars == lineLength - 1) { 21 | output->write(start, chars); 22 | output->write("=\r\n"); 23 | start += chars; 24 | chars = 0; 25 | } 26 | } 27 | output->write(start, chars); 28 | return maxLength; 29 | } 30 | -------------------------------------------------------------------------------- /src/mime/src/mimetext.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012 - Tőkés Attila 3 | 4 | This file is part of SmtpClient for Qt. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | See the LICENSE file for more details. 17 | */ 18 | 19 | #include "mimetext.h" 20 | 21 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 22 | #include 23 | #else 24 | #include 25 | #endif 26 | 27 | /* [1] Constructors and Destructors */ 28 | 29 | MimeText::MimeText(const QString &txt) 30 | { 31 | this->text = txt; 32 | this->cType = "text/plain"; 33 | this->cCharset = "utf-8"; 34 | this->cEncoding = _8Bit; 35 | } 36 | 37 | MimeText::~MimeText() { } 38 | 39 | /* [1] --- */ 40 | 41 | 42 | /* [2] Getters and Setters */ 43 | 44 | void MimeText::setText(const QString & text) 45 | { 46 | this->text = text; 47 | } 48 | 49 | const QString & MimeText::getText() const 50 | { 51 | return text; 52 | } 53 | 54 | /* [2] --- */ 55 | 56 | 57 | /* [3] Protected Methods */ 58 | 59 | void MimeText::writeContent(QIODevice &device) const { 60 | #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) 61 | MimePart::writeContent(device, QStringEncoder(this->cCharset.toStdString().c_str()).encode(text)); 62 | #else 63 | MimePart::writeContent(device, QTextEncoder(QTextCodec::codecForName(this->cCharset.toStdString().c_str())).fromUnicode(text)); 64 | #endif 65 | } 66 | 67 | /* [3] --- */ 68 | -------------------------------------------------------------------------------- /src/mime/src/quotedprintable.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012 - Tőkés Attila 3 | 4 | This file is part of SmtpClient for Qt. 5 | 6 | This library is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU Lesser General Public 8 | License as published by the Free Software Foundation; either 9 | version 2.1 of the License, or (at your option) any later version. 10 | 11 | This library is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | Lesser General Public License for more details. 15 | 16 | See the LICENSE file for more details. 17 | */ 18 | 19 | #include "quotedprintable.h" 20 | 21 | QString QuotedPrintable::encode(const QByteArray &input) 22 | { 23 | static const char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; 24 | 25 | QString output; 26 | 27 | for (int i = 0; i < input.length() ; ++i) 28 | { 29 | const char byte = input[i]; 30 | 31 | if ((byte == 0x20) || ((byte >= 33) && (byte <= 126) && (byte != 61))) { 32 | output.append(byte); 33 | } 34 | else { 35 | output.append('=').append(hex[((byte >> 4) & 0x0F)]).append(hex[(byte & 0x0F)]); 36 | } 37 | } 38 | 39 | return output; 40 | } 41 | 42 | 43 | QByteArray QuotedPrintable::decode(const QString &input) 44 | { 45 | // 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F 46 | static const int hexVal[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, 13, 14, 15}; 47 | 48 | QByteArray output; 49 | 50 | int len = input.length(); 51 | int i; 52 | for (i = 0; i < len-2; ++i) 53 | { 54 | if (input.at(i).toLatin1() == '=') 55 | { 56 | int x = input.at(i+1).toLatin1() - '0'; 57 | int y = input.at(i+2).toLatin1() - '0'; 58 | if (x >= 0 && y >= 0 && x < 23 && y < 23) { 59 | output.append(char((hexVal[x] << 4) + hexVal[y])); 60 | } 61 | else { 62 | output.append('=').append(char(x + '0')).append(char(y + '0')); 63 | } 64 | 65 | i += 2; 66 | } 67 | else 68 | { 69 | output.append(input.at(i).toLatin1()); 70 | } 71 | } 72 | 73 | while (i 2 | #include "tianyamodel.hpp" 3 | 4 | TianyaModel::TianyaModel(QObject* parent) 5 | : QAbstractTableModel(parent) 6 | { 7 | qRegisterMetaType("list_info"); 8 | } 9 | 10 | void TianyaModel::update_tianya_list(const list_info& hits_info) 11 | { 12 | // 计算待插入位置 13 | auto insert_point = std::find_if(std::begin(m_list_info), std::end(m_list_info), [hits_info](const list_info& a){ 14 | return a.hits < hits_info.hits; 15 | }); 16 | 17 | // 避免重复 18 | if (insert_point != std::end(m_list_info)) 19 | { 20 | if(std::end(m_list_info) != std::find_if(std::begin(m_list_info), std::end(m_list_info), 21 | [hits_info](const list_info& a){return a.post_url == hits_info.post_url;}) 22 | ){ 23 | return; 24 | } 25 | }else if (m_list_info.size() && m_list_info.rbegin()->post_url == hits_info.post_url) 26 | { 27 | return; 28 | } 29 | 30 | auto offset = insert_point - m_list_info.begin(); 31 | 32 | beginInsertRows(QModelIndex(), offset, offset); 33 | m_list_info.insert(insert_point, hits_info); 34 | endInsertRows(); 35 | } 36 | 37 | QVariant TianyaModel::headerData(int section, Qt::Orientation orientation, int role) const 38 | { 39 | if (role == Qt::DisplayRole) 40 | { 41 | if (orientation == Qt::Horizontal) { 42 | switch (section) 43 | { 44 | case 0: 45 | return QStringLiteral("标题"); 46 | case 1: 47 | return QStringLiteral("作者"); 48 | case 2: 49 | return QStringLiteral("点击"); 50 | case 3: 51 | return QStringLiteral("回复"); 52 | case 4: 53 | return QStringLiteral("时间"); 54 | case 5: 55 | return QStringLiteral("链接"); 56 | } 57 | } 58 | } 59 | return QVariant(); 60 | 61 | return QAbstractItemModel::headerData(section, orientation, role); 62 | } 63 | 64 | 65 | QVariant TianyaModel::data(const QModelIndex& index, int role) const 66 | { 67 | // 向 GUI 提供格式化好的数据 68 | auto size = m_list_info.size(); 69 | 70 | if (index.row() < size) 71 | { 72 | if(index.parent().isValid()) 73 | return QVariant(); 74 | 75 | const list_info& info = m_list_info[index.row()]; 76 | //index.row() 77 | if (role == Qt::DisplayRole) 78 | { 79 | switch(index.column()) 80 | { 81 | case 0: 82 | return QString::fromStdWString(info.title); 83 | case 1: 84 | return QString::fromStdWString(info.author); 85 | case 2: 86 | return info.hits; 87 | case 3: 88 | return info.replys; 89 | case 4: 90 | return QString::fromStdWString(info.post_time); 91 | case 5: 92 | return QString::fromStdString(info.post_url); 93 | default: 94 | return QVariant(); 95 | } 96 | } 97 | else if (role == Qt::UserRole+1) 98 | { 99 | return QUrl(QString::fromStdString(info.post_url)); 100 | } 101 | else if (role == Qt::UserRole+2) 102 | { 103 | QVariant v; 104 | v.setValue(info); 105 | return v; 106 | } 107 | else if (role == Qt::UserRole+3) 108 | { 109 | switch(index.column()) 110 | { 111 | case 0: 112 | return QString::fromStdWString(info.title); 113 | case 1: 114 | return QString::fromStdWString(info.author); 115 | default: 116 | return QVariant(); 117 | } 118 | } 119 | } 120 | 121 | return QVariant(); 122 | } 123 | 124 | int TianyaModel::columnCount(const QModelIndex& parent) const 125 | { 126 | if(parent.isValid()) 127 | return 0; 128 | return 6; 129 | } 130 | 131 | int TianyaModel::rowCount(const QModelIndex& parent) const 132 | { 133 | if(parent.isValid()) 134 | return 0; 135 | 136 | auto size = m_list_info.size(); 137 | 138 | return size; 139 | } 140 | 141 | QModelIndex TianyaModel::index(int row, int column, const QModelIndex& parent) const 142 | { 143 | return createIndex(row, column); 144 | } 145 | -------------------------------------------------------------------------------- /src/model/tianyamodel.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | Q_DECLARE_METATYPE(list_info) 7 | 8 | class TianyaModel : public QAbstractTableModel 9 | { 10 | Q_OBJECT 11 | public: 12 | 13 | explicit TianyaModel(QObject* parent = 0); 14 | virtual ~TianyaModel(){} 15 | 16 | Q_INVOKABLE void update_tianya_list(const list_info& hits_info); 17 | 18 | public: 19 | virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; 20 | virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const Q_DECL_OVERRIDE; 21 | virtual int columnCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE; 22 | virtual int rowCount(const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE; 23 | virtual QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const Q_DECL_OVERRIDE; 24 | private: 25 | std::vector m_list_info; 26 | }; 27 | -------------------------------------------------------------------------------- /src/novelviewer.hpp: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | #include 16 | #include "tianya_download.hpp" 17 | 18 | 19 | #include "ui_novelviewer.h" 20 | 21 | class NovelViewer : public QMainWindow 22 | { 23 | Q_OBJECT 24 | 25 | Q_PROPERTY(bool filter_reply READ filter_reply WRITE set_filter_reply); 26 | 27 | public: 28 | explicit NovelViewer(boost::asio::io_service&, list_info, QWidget *parent = 0); 29 | virtual ~NovelViewer(); 30 | 31 | bool filter_reply(); 32 | 33 | protected: 34 | void changeEvent(QEvent *e); 35 | 36 | private Q_SLOTS: 37 | void text_brower_stay_on_top(); 38 | void download_complete(); 39 | 40 | void save_to_file(QString); 41 | 42 | void save_to(); 43 | void showfind_widget(); 44 | void hidefind_widget(); 45 | void set_filter_reply(bool); 46 | 47 | void mail_to(); 48 | 49 | 50 | private: 51 | Ui::NovelViewer ui; 52 | 53 | QShortcut m_esc, temp_shortcut; 54 | 55 | boost::asio::io_service& m_io_service; 56 | std::wstring m_title; 57 | tianya_download m_tianya_download; 58 | 59 | QAction* m_action_send_to_kindle; 60 | QAction* m_action_save_to_file; 61 | QToolBar* m_toolbar; 62 | QProgressBar* m_progress_bar; 63 | QVBoxLayout* textBrowser_layout; 64 | QWidget* findwindow = nullptr; 65 | }; 66 | -------------------------------------------------------------------------------- /src/novelviewer.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | NovelViewer 4 | 5 | 6 | 7 | 0 8 | 0 9 | 748 10 | 473 11 | 12 | 13 | 14 | MainWindow 15 | 16 | 17 | 18 | 19 | 20 | 21 | QFrame::Plain 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by avbot.rc 4 | // 5 | #define IDI_TIANYA_ICON 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 103 12 | #define _APS_NEXT_COMMAND_VALUE 40000 13 | #define _APS_NEXT_CONTROL_VALUE 1000 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /src/sendprogress.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include 3 | #include 4 | #include 5 | 6 | #include "sendprogress.hpp" 7 | 8 | SendProgress::SendProgress(boost::asio::io_service& io, const list_info& info, QWidget* parent) 9 | : QGroupBox(parent) 10 | , m_tianya_download(io, info, true) 11 | { 12 | // 连接 signals 以更新 UI 13 | ui.setupUi(this); 14 | 15 | ui.progressBar->setFormat(QStringLiteral("%p% - (正在下载全文)")); 16 | ui.progressBar->setValue(0); 17 | 18 | QObject::connect(&m_tianya_download, SIGNAL(download_progress_report(double)), this, SLOT(set_download_work_percent(double))); 19 | QObject::connect(&m_tianya_download, SIGNAL(download_complete()), this, SLOT(start_sendmail())); 20 | 21 | ui.label_title->setText(QString::fromStdWString(info.title)); 22 | } 23 | 24 | void SendProgress::start() 25 | { 26 | m_tianya_download.start_download(); 27 | } 28 | 29 | void SendProgress::set_download_work_percent(double v) 30 | { 31 | ui.progressBar->setValue(v*80); 32 | } 33 | 34 | void SendProgress::set_send_work_percent(double v) 35 | { 36 | ui.progressBar->setValue(80 + v*20); 37 | } 38 | 39 | void SendProgress::start_sendmail() 40 | { 41 | ui.progressBar->setValue(80); 42 | ui.progressBar->setFormat(QStringLiteral("%p% - (正在发送邮件)")); 43 | 44 | 45 | QSettings settings; 46 | 47 | EmailAddress mail_rcpt(settings.value("kindle.kindlemail").toString()); 48 | 49 | QObject::connect(&m_tianya_download, SIGNAL(mailsend_progress_report(double)), this, SLOT(set_send_work_percent(double))); 50 | QObject::connect(&m_tianya_download, SIGNAL(send_complete()), this, SLOT(mail_sended())); 51 | 52 | m_tianya_download.start_send_mail(mail_rcpt); 53 | } 54 | 55 | void SendProgress::mail_sended() 56 | { 57 | QTimer::singleShot(2000, this, SLOT(deleteLater())); 58 | 59 | ui.progressBar->setValue(100); 60 | ui.progressBar->setFormat(QStringLiteral("%p% - (完成)")); 61 | } 62 | 63 | 64 | -------------------------------------------------------------------------------- /src/sendprogress.hpp: -------------------------------------------------------------------------------- 1 |  2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | #include "tianya_download.hpp" 8 | #include "ui_sendprogress.h" 9 | 10 | class SendProgress : public QGroupBox 11 | { 12 | Q_OBJECT 13 | public: 14 | explicit SendProgress(boost::asio::io_service&, const list_info&, QWidget* parent = 0); 15 | 16 | public Q_SLOTS: 17 | 18 | // 开始. 19 | void start(); 20 | 21 | 22 | private Q_SLOTS: 23 | 24 | void start_sendmail(); 25 | 26 | void set_download_work_percent(double); 27 | void set_send_work_percent(double); 28 | 29 | void mail_sended(); 30 | 31 | private: 32 | Ui::SendProgress ui; 33 | 34 | tianya_download m_tianya_download; 35 | }; 36 | -------------------------------------------------------------------------------- /src/sendprogress.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | SendProgress 4 | 5 | 6 | 7 | 0 8 | 0 9 | 596 10 | 99 11 | 12 | 13 | 14 | 15 | 0 16 | 0 17 | 18 | 19 | 20 | 发送中 .... 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 0 30 | 0 31 | 32 | 33 | 34 | 标题: 35 | 36 | 37 | 38 | 39 | 40 | 41 | 小说标题 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 24 53 | 54 | 55 | 56 | 57 | 58 | 59 | 取消 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | Qt::Vertical 69 | 70 | 71 | QSizePolicy::MinimumExpanding 72 | 73 | 74 | 75 | 0 76 | 13 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /src/smtpclient/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | include_directories(${Boost_INCLUDE_DIRS}) 3 | 4 | add_library(smtpclient STATIC smtp.cpp smtp.hpp) 5 | 6 | -------------------------------------------------------------------------------- /src/smtpclient/smtp.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include 3 | #include 4 | #include 5 | 6 | #include "smtp.hpp" 7 | namespace mx { 8 | namespace detail { 9 | smtp::smtp( boost::asio::io_service& _io_service, std::string user, std::string passwd, std::string _mailserver ) 10 | : io_service( _io_service ) 11 | , m_work(io_service) 12 | , m_mailaddr( user ) 13 | , m_passwd( passwd ) 14 | , m_mailserver( _mailserver ) 15 | , m_mailserver_query( "smtp.qq.com", "25" ) 16 | { 17 | // 计算 m_AUTH 18 | std::vector authtoken( user.length() + passwd.length() + 2 ); 19 | std::copy( user.begin(), user.end(), &authtoken[1] ); 20 | std::copy( passwd.begin(), passwd.end(), &authtoken[user.length() + 2] ); 21 | 22 | //ADQ2NDg5MzQ5MAB0ZXN0cGFzc3dk 23 | m_AUTH = boost::base64_encode( std::string( authtoken.data(), authtoken.size() ) ); 24 | 25 | if( m_mailserver.empty() ) { // 自动从 mailaddress 获得. 26 | if( m_mailaddr.find( "@" ) == std::string::npos ) 27 | m_mailserver = "smtp.qq.com"; // 如果 邮箱是 qq 号码(没@),就默认使用 smtp.qq.com . 28 | else 29 | m_mailserver = std::string( "smtp." ) + m_mailaddr.substr( m_mailaddr.find_last_of( "@" ) + 1 ); 30 | } 31 | 32 | boost::cmatch what; 33 | 34 | if( boost::regex_search( m_mailserver.c_str(), what, boost::regex( "(.*):([0-9]+)" ) ) ) { 35 | m_mailserver_query.~basic_resolver_query(); 36 | 37 | std::construct_at(&m_mailserver_query, what[1].str(), what[2].str() ); 38 | } else { 39 | m_mailserver_query.~basic_resolver_query(); 40 | std::construct_at(&m_mailserver_query, m_mailserver, "25" ); 41 | } 42 | } 43 | 44 | void smtp::server_cap_handler( std::string cap ) 45 | { 46 | boost::cmatch what; 47 | 48 | // 如果有 STARTTLS , 就执行 STARTTLS 开启 TLS 加密 49 | if( cap == "STARTTLS" ) { 50 | using namespace boost::asio::ssl; 51 | using namespace boost::asio::ip; 52 | m_sslctx.reset( new context( context::tlsv1_client ) ); 53 | m_sslsocket.reset( 54 | new stream( *m_socket, *m_sslctx ) 55 | ); 56 | } 57 | } 58 | 59 | } 60 | 61 | smtp::smtp( boost::asio::io_service& _io_service, std::string user, std::string passwd, std::string _mailserver ) 62 | : impl_smtp( _io_service, user, passwd, _mailserver ) 63 | { 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /src/smtpclient/smtptest.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | namespace fs = boost::filesystem; 3 | #include 4 | namespace po = boost::program_options; 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #include "internet_mail_format.hpp" 20 | #include 21 | 22 | #include "smtp.hpp" 23 | 24 | static boost::asio::io_service io; 25 | static void sended( const boost::system::error_code & ec ) 26 | { 27 | std::cout << ec.message() << std::endl; 28 | 29 | io.stop(); 30 | } 31 | 32 | #include "fsconfig.ipp" 33 | 34 | int main( int argc, char * argv[] ) 35 | { 36 | std::string qqnumber, qqpwd; 37 | std::string ircnick, ircroom, ircpwd; 38 | std::string xmppuser, xmppserver, xmpppwd, xmpproom; 39 | std::string cfgfile; 40 | std::string logdir; 41 | std::string chanelmap; 42 | std::string mailaddr, mailpasswd, mailserver; 43 | 44 | setlocale( LC_ALL, "" ); 45 | 46 | po::options_description desc( "qqbot options" ); 47 | desc.add_options() 48 | ( "version,v", "output version" ) 49 | ( "help,h", "produce help message" ) 50 | ( "daemon,d", "go to background" ) 51 | ( "mail", po::value( &mailaddr ), "send mail by this address" ) 52 | ( "mailpasswd", po::value( &mailpasswd ), "password of mail" ) 53 | ( "mailserver", po::value( &mailserver ), "server to use" ) 54 | ; 55 | 56 | po::variables_map vm; 57 | po::store( po::parse_command_line( argc, argv, desc ), vm ); 58 | po::notify( vm ); 59 | 60 | if( vm.count( "help" ) ) { 61 | std::cerr << desc << std::endl; 62 | return 1; 63 | } 64 | 65 | if( vm.size() == 0 ) { 66 | try { 67 | fs::path p = configfilepath(); 68 | po::store( po::parse_config_file( p.string().c_str(), desc ), vm ); 69 | po::notify( vm ); 70 | } catch( char* e ) { 71 | std::cerr << e << std::endl; 72 | } 73 | } 74 | 75 | mx::smtp smtp( io, mailaddr, mailpasswd, mailserver ); 76 | InternetMailFormat imf; 77 | 78 | imf.header["from"] = mailaddr; 79 | imf.header["to"] = "\"晕菜\" <406679186@qq.com>"; 80 | imf.header["subject"] = "test mail"; 81 | imf.header["content-type"] = "text/plain; charset=utf8"; 82 | 83 | imf.body = "test body dasdfasd "; 84 | std::stringstream maildata; 85 | boost::asio::streambuf buf; 86 | std::ostream os( &buf ); 87 | imf_write_stream( imf, os ); 88 | 89 | std::string _mdata = boost::asio::buffer_cast( buf.data() ); 90 | 91 | smtp.async_sendmail( imf, sended); 92 | boost::asio::io_service::work work(io); 93 | avloop_run(io); 94 | } 95 | -------------------------------------------------------------------------------- /src/syncobj.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include 3 | #include 4 | #include "syncobj.hpp" 5 | 6 | void SyncObjec::do_post(std::function func) 7 | { 8 | Q_EMIT post(func); 9 | } 10 | 11 | SyncObjec::SyncObjec() 12 | { 13 | qRegisterMetaType>("std::function"); 14 | connect(this, &SyncObjec::post, this, &SyncObjec::on_post, Qt::QueuedConnection); 15 | } 16 | -------------------------------------------------------------------------------- /src/syncobj.hpp: -------------------------------------------------------------------------------- 1 |  2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | void post_on_gui_thread(std::function); 9 | 10 | class SyncObjec : public QObject 11 | { 12 | Q_OBJECT 13 | 14 | void do_post(std::function func); 15 | 16 | private Q_SLOTS: 17 | void on_post(std::function qfunc_ptr){(qfunc_ptr)();} 18 | 19 | Q_SIGNALS: 20 | void post(std::function); 21 | 22 | public: 23 | SyncObjec(); 24 | virtual ~SyncObjec(){} 25 | 26 | friend void post_on_gui_thread(std::function); 27 | 28 | }; 29 | -------------------------------------------------------------------------------- /src/tianya-radar.desktop: -------------------------------------------------------------------------------- 1 | [Desktop Entry] 2 | Name=Tianya Radar 3 | Name[zh_CN]=天涯阅读器 4 | 5 | GenericName=Tianya Radar 6 | GenericName[zh_CN]=天涯雷达 7 | 8 | Comment=search novel in tianya 9 | Comment[zh_CN]=搜索天涯小说 10 | 11 | Icon=tianya 12 | 13 | Type=Application 14 | Categories=Network;Qt; 15 | 16 | Exec=tianya 17 | StartupNotify=false 18 | Terminal=false 19 | -------------------------------------------------------------------------------- /src/tianya.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avplayer/tianya/e3cb300de8bec228dac5b6a6ffe974acd00ff8b1/src/tianya.ico -------------------------------------------------------------------------------- /src/tianya.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | tianya.svg 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/tianya.rc.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/avplayer/tianya/e3cb300de8bec228dac5b6a6ffe974acd00ff8b1/src/tianya.rc.in -------------------------------------------------------------------------------- /src/tianya_download.cpp: -------------------------------------------------------------------------------- 1 |  2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "mimemessage.h" 11 | #include "mimeattachment.h" 12 | #include "mimetext.h" 13 | 14 | #include "syncobj.hpp" 15 | #include "tianya_download.hpp" 16 | 17 | tianya_download::tianya_download(boost::asio::io_service& io, const list_info& info, bool filter_reply, QObject* parent) 18 | : QObject(parent) 19 | , m_io_service(io) 20 | , m_tianya_context(std::make_shared(std::ref(io))) 21 | , m_list_info(info) 22 | , m_first_chunk(true) 23 | , m_is_gone(std::make_shared(false)) 24 | { 25 | auto is_gone = m_is_gone; 26 | m_connection_notify_chunk = m_tianya_context->connect_one_content_fetched([this, is_gone](std::wstring content) 27 | { 28 | double progressprecent = (double)m_tianya_context->page_index() / (double) m_tianya_context->page_count(); 29 | post_on_gui_thread([this, is_gone, content, progressprecent]() 30 | { 31 | if (*is_gone) 32 | return; 33 | chunk_download_notify(QString::fromStdWString(content)); 34 | 35 | download_progress_report(progressprecent); 36 | 37 | if (m_first_chunk) 38 | { 39 | m_first_chunk = false; 40 | 41 | QTimer::singleShot(200, this, [this](){timed_first_timershot();}); 42 | } 43 | }); 44 | }); 45 | 46 | m_connection_notify_complete = m_tianya_context->connect_download_complete([this, is_gone]() 47 | { 48 | post_on_gui_thread([this, is_gone]() 49 | { 50 | if (*is_gone) 51 | return; 52 | download_complete(); 53 | }); 54 | }); 55 | 56 | m_tianya_context->filter_reply(filter_reply); 57 | } 58 | 59 | bool tianya_download::filter_reply() 60 | { 61 | return m_tianya_context->filter_reply(); 62 | } 63 | 64 | void tianya_download::set_filter_reply(bool v) 65 | { 66 | m_tianya_context->filter_reply(v); 67 | } 68 | 69 | tianya_download::~tianya_download() 70 | { 71 | *m_is_gone = true; 72 | m_connection_notify_complete.disconnect(); 73 | m_connection_notify_chunk.disconnect(); 74 | 75 | m_tianya_context->stop(); 76 | } 77 | 78 | void tianya_download::start_download() 79 | { 80 | m_tianya_context->start(m_list_info.post_url); 81 | } 82 | 83 | void tianya_download::save_to_file(QString filename) 84 | { 85 | std::shared_ptr filestream = std::make_shared(filename); 86 | 87 | filestream->open(QFile::WriteOnly); 88 | 89 | if (filestream->isOpen()) 90 | { 91 | // add BOM 92 | filestream->write("\357\273\277", 3); 93 | 94 | auto _tianya_context = m_tianya_context; 95 | 96 | m_io_service.post([filestream, _tianya_context]() 97 | { 98 | _tianya_context->serialize_to_io_device(filestream.get()); 99 | }); 100 | } 101 | } 102 | 103 | void tianya_download::start_send_mail(EmailAddress mail_rcpt) 104 | { 105 | QSettings settings; 106 | 107 | EmailAddress mail_sender(settings.value("kindle.usermail").toString(), "Tianya Radar"); 108 | QString password = settings.value("kindle.usermail_passwd").toString(); 109 | 110 | m_smtp.reset(new mx::smtp(m_io_service, mail_sender.getAddress().toStdString(), password.toUtf8().toStdString())); 111 | 112 | InternetMailFormat imf; 113 | 114 | imf.header["from"] = mail_sender.getAddress().toStdString(); 115 | imf.header["to"] = mail_rcpt.getAddress().toStdString(); 116 | imf.header["subject"] = "Convert"; 117 | 118 | std::shared_ptr message = std::make_shared(); 119 | 120 | message->setSender(mail_sender); 121 | message->addRecipient(mail_rcpt); 122 | message->setSubject("Convert"); 123 | 124 | QBuffer articlecontent; 125 | articlecontent.open(QBuffer::ReadWrite); 126 | 127 | m_tianya_context->serialize_to_io_device(&articlecontent); 128 | 129 | articlecontent.seek(0); 130 | 131 | std::shared_ptr attachment; 132 | 133 | attachment.reset(new MimeAttachment(articlecontent.buffer(), QStringLiteral("%1.txt").arg(QString::fromStdWString(m_list_info.title)))); 134 | attachment->setCharset("utf-8"); 135 | attachment->setContentType("text/plain"); 136 | 137 | message->addPart(attachment.get()); 138 | 139 | mailsend_progress_report(0.5); 140 | 141 | imf.custom_data = [message, attachment](std::ostream* o) 142 | { 143 | *o << message->toString().toStdString(); 144 | }; 145 | 146 | auto is_gone = m_is_gone; 147 | m_smtp->async_sendmail(imf, [this, is_gone](const boost::system::error_code & ec) 148 | { 149 | if (*is_gone) 150 | return; 151 | 152 | post_on_gui_thread([this, is_gone]() 153 | { 154 | if (*is_gone) 155 | return; 156 | // nice 157 | mailsend_progress_report(1.0); 158 | 159 | send_complete(); 160 | }); 161 | }); 162 | } 163 | 164 | -------------------------------------------------------------------------------- /src/tianya_download.hpp: -------------------------------------------------------------------------------- 1 |  2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include "emailaddress.h" 10 | #include "smtpclient/smtp.hpp" 11 | 12 | class tianya_download : public QObject 13 | { 14 | Q_OBJECT 15 | 16 | Q_PROPERTY(bool filter_reply READ filter_reply WRITE set_filter_reply); 17 | 18 | public: 19 | explicit tianya_download(boost::asio::io_service&, const list_info&, bool filter_reply = false, QObject* parent = 0); 20 | 21 | virtual ~tianya_download(); 22 | 23 | bool filter_reply(); 24 | 25 | std::shared_ptr get_tianya_context(){return m_tianya_context;} 26 | 27 | public Q_SLOTS: 28 | void set_filter_reply(bool); 29 | 30 | void start_download(); 31 | 32 | void save_to_file(QString); 33 | 34 | void start_send_mail(EmailAddress); 35 | 36 | 37 | Q_SIGNALS: 38 | void download_complete(); 39 | void chunk_download_notify(QString); 40 | void timed_first_timershot(); 41 | 42 | void send_complete(); 43 | 44 | void download_progress_report(double); 45 | void mailsend_progress_report(double); 46 | 47 | private: 48 | boost::asio::io_service& m_io_service; 49 | list_info m_list_info; 50 | 51 | boost::signals2::scoped_connection m_connection_notify_chunk; 52 | boost::signals2::scoped_connection m_connection_notify_complete; 53 | 54 | std::shared_ptr m_tianya_context; 55 | std::shared_ptr m_smtp; 56 | 57 | std::shared_ptr m_is_gone; 58 | bool m_first_chunk; 59 | }; 60 | 61 | -------------------------------------------------------------------------------- /src/tianyawindow.hpp: -------------------------------------------------------------------------------- 1 |  2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include "model/tianyamodel.hpp" 11 | 12 | #include "ui_tianyawindow.h" 13 | 14 | class TianyaWindow : public QMainWindow 15 | { 16 | Q_OBJECT 17 | 18 | public: 19 | explicit TianyaWindow(boost::asio::io_service& , QWidget* parent = 0); 20 | virtual ~TianyaWindow(); 21 | 22 | protected: 23 | virtual void changeEvent(QEvent *e) Q_DECL_OVERRIDE; 24 | virtual void closeEvent(QCloseEvent*) Q_DECL_OVERRIDE; 25 | 26 | private Q_SLOTS: 27 | void on_tableView_doubleClicked(const QModelIndex &index); 28 | void timer_adjust_Column(); 29 | void real_start_tianya(); 30 | void pop_up_context_menu(QPoint); 31 | void kindle_settings(bool); 32 | 33 | private: 34 | Ui::TianyaWindow ui; 35 | boost::asio::io_service& m_io_service; 36 | 37 | bool m_fist_insertion; 38 | 39 | tianya_list m_tianya; 40 | 41 | TianyaModel m_tianya_data_mode; 42 | QSortFilterProxyModel m_sortproxy_for_tianya_data_mode; 43 | 44 | std::string m_post_url; 45 | }; 46 | -------------------------------------------------------------------------------- /src/tianyawindow.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | TianyaWindow 4 | 5 | 6 | 7 | 0 8 | 0 9 | 800 10 | 600 11 | 12 | 13 | 14 | TianYa Radar 15 | 16 | 17 | 18 | 19 | 20 | 21 | Qt::CustomContextMenu 22 | 23 | 24 | true 25 | 26 | 27 | QAbstractItemView::ExtendedSelection 28 | 29 | 30 | QAbstractItemView::SelectRows 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Qt::NoContextMenu 39 | 40 | 41 | 42 | 43 | 44 | 0 45 | 0 46 | 800 47 | 30 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | --------------------------------------------------------------------------------