├── data ├── favicon.xcf ├── favicon_i.png ├── favicon_p.png ├── favicon_s.png └── favicon_missing.png ├── .gitignore ├── src ├── pages │ ├── png++ │ │ ├── AUTHORS │ │ ├── BUGS │ │ ├── TODO │ │ ├── ChangeLog │ │ ├── NEWS │ │ ├── COPYING │ │ ├── palette.hpp │ │ ├── tRNS.hpp │ │ ├── INSTALL │ │ ├── config.hpp │ │ ├── README │ │ ├── color.hpp │ │ ├── end_info.hpp │ │ ├── info_base.hpp │ │ ├── packed_pixel.hpp │ │ ├── ga_pixel.hpp │ │ ├── error.hpp │ │ ├── rgb_pixel.hpp │ │ ├── rgba_pixel.hpp │ │ ├── pixel_traits.hpp │ │ ├── index_pixel.hpp │ │ └── gray_pixel.hpp │ ├── HomePage.hpp │ ├── PostPage.hpp │ ├── RssPage.hpp │ ├── FaviconPage.hpp │ ├── NotFoundPage.hpp │ ├── OpenSearchPage.hpp │ ├── SavePage.hpp │ ├── IndexStubPage.hpp │ ├── TagSearchPage.hpp │ ├── IndexPage.hpp │ ├── ProxyPage.hpp │ ├── IndexStubPage.cpp │ ├── HomePage.cpp │ ├── NotFoundPage.cpp │ ├── PageHandler.hpp │ ├── UrlHandler.hpp │ ├── TagSearchPage.cpp │ ├── PageHandler.cpp │ ├── FilePage.hpp │ ├── OpenSearchPage.cpp │ ├── APage.hpp │ ├── PostPage.cpp │ ├── RssPage.cpp │ ├── SavePage.cpp │ ├── Styler.hpp │ ├── FaviconPage.cpp │ ├── APage.cpp │ ├── ProxyPage.cpp │ └── FilePage.cpp ├── objects │ ├── Index.cpp │ ├── Tag.cpp │ ├── Note.cpp │ ├── Pool.cpp │ ├── Comment.cpp │ ├── Pool.hpp │ ├── Comment.hpp │ ├── Note.hpp │ ├── Identity.hpp │ ├── Tag.hpp │ ├── Image.hpp │ ├── Index.hpp │ ├── Image.cpp │ ├── Resource.hpp │ ├── ResourceHandler.hpp │ └── Post.hpp ├── db │ ├── AddLocal.hpp │ ├── Database.hpp │ ├── Database.cpp │ ├── LocalDb.hpp │ ├── AddLocal.cpp │ ├── Statement.hpp │ └── Booru.hpp ├── system │ ├── Thumbnailer.hpp │ ├── Thumbnailer-fallback.cpp │ ├── TimeHandling.cpp │ ├── TimeHandling.hpp │ └── Thumbnailer-kde.cpp ├── main.cpp ├── exceptions │ ├── InvalidInput.hpp │ ├── ResourceMissing.hpp │ └── utils.hpp ├── server │ ├── Server.hpp │ ├── ArgsParsing.hpp │ ├── ArgsParsing.cpp │ └── PocoServer.cpp ├── api │ ├── ApiHandler.hpp │ ├── BehoimiApi.hpp │ ├── IdolApi.hpp │ ├── YandereApi.hpp │ ├── KonachanApi.cpp │ ├── LocalApi.cpp │ ├── LocalApi.hpp │ ├── SanApi.hpp │ ├── KonachanApi.hpp │ ├── ApiHandler.cpp │ ├── ShimmieApi.hpp │ └── Api.hpp └── parsing │ ├── DataNodeInterface.hpp │ ├── NullDataNode.hpp │ ├── JsonDataNode.hpp │ ├── OpenSearchDescription.cpp │ ├── Rss.cpp │ ├── OpenSearchDescription.hpp │ ├── DataNode.hpp │ ├── pugiconfig.hpp │ └── StringViewUtils.hpp ├── README.md ├── styles ├── _grail.scss ├── _header.scss └── _post.scss ├── premake4.lua ├── resources └── infinity.js └── CMakeLists.txt /data/favicon.xcf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spillerrec/BooruSurfer2/HEAD/data/favicon.xcf -------------------------------------------------------------------------------- /data/favicon_i.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spillerrec/BooruSurfer2/HEAD/data/favicon_i.png -------------------------------------------------------------------------------- /data/favicon_p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spillerrec/BooruSurfer2/HEAD/data/favicon_p.png -------------------------------------------------------------------------------- /data/favicon_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spillerrec/BooruSurfer2/HEAD/data/favicon_s.png -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /premake4.exe 2 | /Makefile 3 | 4 | /bin 5 | /build 6 | /.sass-cache 7 | /cmake_build 8 | -------------------------------------------------------------------------------- /data/favicon_missing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/spillerrec/BooruSurfer2/HEAD/data/favicon_missing.png -------------------------------------------------------------------------------- /src/pages/png++/AUTHORS: -------------------------------------------------------------------------------- 1 | png++ is written by Alexander Shulgin (alex dot shulgin at gmail dot com) 2 | Copyright (C) 2007,2008 3 | 4 | When writing to me be sure to put png++: in the subject :-) 5 | -------------------------------------------------------------------------------- /src/pages/png++/BUGS: -------------------------------------------------------------------------------- 1 | This file lists known bugs and limitations in png++: 2 | 3 | - Lacks support for output transformations 4 | 5 | - Lacks support for optional/unknown chunks in PNG data stream 6 | 7 | - Documentation sucks 8 | 9 | 10 | To report bugs, please use Savannah bug tracker: 11 | http://savannah.nongnu.org/bugs/?group=pngpp&func=additem 12 | 13 | Do not forget to check if the bug was already filed. :-) 14 | -------------------------------------------------------------------------------- /src/objects/Index.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "Index.hpp" 18 | 19 | 20 | -------------------------------------------------------------------------------- /src/objects/Tag.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "Tag.hpp" 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/objects/Note.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "Note.hpp" 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/objects/Pool.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "Pool.hpp" 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/objects/Comment.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "Comment.hpp" 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | BooruSurfer2 2 | ============ 3 | [![GitHub license](https://img.shields.io/badge/license-GPLv3-blue.svg?style=flat-square)](https://www.gnu.org/licenses/gpl-3.0.txt) 4 | 5 | BooruSurfer2 is a remake of BooruSurfer, however ported from PHP to C++. The goal of BooruSurfer is to provide a consistent and space-efficient interface to Booru-like image boards, using a web browser as front end. BooruSurfer2 attempts to improve performance in parallel situations, where PHP showed to be impractical. Furthermore, it attempts to integrate a personal image collection into the experience. 6 | 7 | NOTE: Still very much work in progress 8 | 9 | ### Dependencies 10 | 11 | - C++14 compiler 12 | - Poco with Crypto/NetSSL 13 | - jansson 14 | - tidy-html5 15 | - sqlite3 16 | - libpng 17 | - sass (and therefore Ruby) -------------------------------------------------------------------------------- /styles/_grail.scss: -------------------------------------------------------------------------------- 1 | @mixin grail-body( $LC-width, $RC-width, $padding ){ 2 | min-width: 2 * ($LC-width + $padding) + $RC-width; /* 2x LC width + RC width */ 3 | overflow: scroll; /* Prevent change of layout when scrollbar changes, no known better solution than to force it on */ 4 | } 5 | 6 | @mixin grail-container( $LC-width, $RC-width, $padding ){ 7 | padding-left: $LC-width + $padding; 8 | } 9 | @mixin grail-center( $LC-width, $RC-width, $padding ){ 10 | position: relative; 11 | float: left; 12 | width: 100%; 13 | } 14 | 15 | @mixin grail-lc( $LC-width, $RC-width, $padding ){ 16 | position: relative; 17 | float: left; 18 | width: $LC-width; /* LC width */ 19 | right: $LC-width + $padding; /* LC width */ 20 | margin-right: -($LC-width + $padding); /* seems to fix issue with this box affecting .comments*/ 21 | margin-left: -100%; 22 | } -------------------------------------------------------------------------------- /src/db/AddLocal.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of rss2rss. 2 | 3 | rss2rss is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | rss2rss is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with rss2rss. If not, see . 15 | */ 16 | 17 | #ifndef ADD_LOCAL_HPP 18 | #define ADD_LOCAL_HPP 19 | 20 | #include 21 | 22 | void addFolder( std::string dir_path ); 23 | 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /src/pages/png++/TODO: -------------------------------------------------------------------------------- 1 | ? add output transformations 2 | + support for non-8bit data 3 | + stream exceptions: badbit only 4 | + adjust png::image for non-memory back end buffer + row-by-row io 5 | + use doxygen 6 | - add optional and unknown chunks handling 7 | + change bit_depth to size_t 8 | + move tests sources to test/, examples to examples/ 9 | + extract common code from generator/consumer 10 | + update pixel traits to detect channels count 11 | + unify template parameters naming 12 | + make sure all headers compile on their own 13 | + add compilation dependency detection 14 | + add pixel_buffer/image::operator[] 15 | + improve docs and README 16 | ? endianness in expand_8_to_16() 17 | - unify error messages (capitalization, etc.) 18 | + move stream template parameter from class to function level in 19 | generator and consumer 20 | + make all tests run even if any of them fails 21 | -------------------------------------------------------------------------------- /src/pages/png++/ChangeLog: -------------------------------------------------------------------------------- 1 | 2009-06-21 Alex Shulgin 2 | 3 | * config.hpp: Added support for FreeBSD (detect endianness). 4 | Patch by . 5 | 6 | png++-0.2.3 19 Oct 2008 7 | 8 | Fixed numerous `already defined' errors due to require_color_space 9 | implementation. Added `config.hpp'. Fixed `strerror' usage. 10 | Minor docs fixes. 11 | 12 | png++-0.2.1 08 Dec 2007 13 | 14 | Added support for tRNS chunk. Added non-std IO streams support. 15 | Fixed 16-bit endianness problems. Improved test script. 16 | 17 | png++-0.2.0 08 Jul 2007 18 | 19 | Major internal code refactoring. Added support for non-8-bit 20 | data, row-by-row IO, added docs, test suite and more. Fixed some 21 | bugs including interlace handling. 22 | 23 | png++-0.1.1 07 Apr 2007 24 | 25 | Added appropriate copyright notices. 26 | 27 | png++-0.1.0 04 Feb 2007 28 | 29 | Initial release. 30 | -------------------------------------------------------------------------------- /src/system/Thumbnailer.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef THUMBNAILER_HPP 18 | #define THUMBNAILER_HPP 19 | 20 | #include 21 | 22 | std::string get_thumbnail( std::string path ); 23 | 24 | #endif 25 | 26 | -------------------------------------------------------------------------------- /src/system/Thumbnailer-fallback.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | 18 | #ifndef WIN32 19 | 20 | #include "Thumbnailer.hpp" 21 | 22 | std::string get_thumbnail( std::string ){ 23 | return {}; 24 | } 25 | 26 | #endif 27 | 28 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include "server/Server.hpp" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef USES_QT 9 | #include 10 | #endif 11 | 12 | int main( int argc, char *argv[] ){ 13 | Poco::Net::initializeNetwork(); 14 | Poco::Net::initializeSSL(); 15 | Poco::Crypto::initializeCrypto(); 16 | 17 | int result = 0; 18 | std::thread poco_thread( [&](){ result = Server().run( argc, argv ); } ); 19 | 20 | #ifdef USES_QT 21 | QGuiApplication qt_app( argc, argv ); 22 | //std::thread qt_thread( [&](){ qt_app.exec(); } ); 23 | qt_app.exec(); 24 | #endif 25 | 26 | poco_thread.join(); 27 | Poco::Net::uninitializeNetwork(); 28 | Poco::Net::uninitializeSSL(); 29 | Poco::Crypto::uninitializeCrypto(); 30 | 31 | #ifdef USES_QT 32 | // qt_app.exit(); 33 | //qt_thread.join(); 34 | #endif 35 | 36 | return result; 37 | } 38 | -------------------------------------------------------------------------------- /src/objects/Pool.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef POOL_HPP 18 | #define POOL_HPP 19 | 20 | #include "Identity.hpp" 21 | 22 | class Pool : public Identity<>{ 23 | private: 24 | 25 | 26 | public: 27 | 28 | 29 | }; 30 | 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /src/objects/Comment.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef COMMENT_HPP 18 | #define COMMENT_HPP 19 | 20 | #include "Identity.hpp" 21 | 22 | class Comment : public Identity<>{ 23 | private: 24 | 25 | 26 | public: 27 | 28 | 29 | }; 30 | 31 | #endif 32 | 33 | -------------------------------------------------------------------------------- /src/pages/HomePage.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef HOME_PAGE_H 18 | #define HOME_PAGE_H 19 | 20 | #include "APage.hpp" 21 | 22 | class HomePage : public StringPage{ 23 | public: 24 | std::string serve( Arguments args, std::vector
&headers ) const override; 25 | }; 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /src/pages/PostPage.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef POST_PAGE_H 18 | #define POST_PAGE_H 19 | 20 | #include "APage.hpp" 21 | 22 | class PostPage : public StringPage{ 23 | public: 24 | std::string serve( Arguments args, std::vector
&headers ) const override; 25 | }; 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /src/pages/RssPage.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef RSS_PAGE_HPP 18 | #define RSS_PAGE_HPP 19 | 20 | #include "APage.hpp" 21 | 22 | class RssPage : public StringPage{ 23 | public: 24 | std::string serve( Arguments args, std::vector
&headers ) const override; 25 | }; 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /src/pages/FaviconPage.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef FAVICON_PAGE_HPP 18 | #define FAVICON_PAGE_HPP 19 | 20 | #include "APage.hpp" 21 | 22 | class FaviconPage : public StringPage{ 23 | public: 24 | std::string serve( Arguments args, std::vector
&headers ) const; 25 | }; 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /src/pages/NotFoundPage.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef NOT_FOUND_PAGE_H 18 | #define NOT_FOUND_PAGE_H 19 | 20 | #include "APage.hpp" 21 | 22 | class NotFoundPage : public StringPage{ 23 | public: 24 | std::string serve( Arguments args, std::vector
&headers ) const override; 25 | }; 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /src/pages/OpenSearchPage.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef OPEN_SEARCH_PAGE_HPP 18 | #define OPEN_SEARCH_PAGE_HPP 19 | 20 | #include "APage.hpp" 21 | 22 | class OpenSearchPage : public StringPage{ 23 | public: 24 | std::string serve( Arguments args, std::vector
&headers ) const; 25 | }; 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /src/pages/SavePage.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef SAVE_PAGE_H 18 | #define SAVE_PAGE_H 19 | 20 | #include "FilePage.hpp" 21 | 22 | 23 | class SavePage : public StringPage{ 24 | public: 25 | virtual std::string serve( Arguments args, std::vector
&headers ) const override; 26 | }; 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /src/pages/IndexStubPage.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef INDEX_STUB_PAGE_HPP 18 | #define INDEX_STUB_PAGE_HPP 19 | 20 | #include "APage.hpp" 21 | 22 | class IndexStubPage : public StringPage{ 23 | public: 24 | std::string serve( Arguments args, std::vector
&headers ) const override; 25 | }; 26 | 27 | #endif 28 | 29 | -------------------------------------------------------------------------------- /src/exceptions/InvalidInput.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef INVALID_INPUT_HPP 18 | #define INVALID_INPUT_HPP 19 | 20 | #include 21 | 22 | class InvalidInput : public std::runtime_error{ 23 | public: 24 | InvalidInput( const std::string& error ) 25 | : std::runtime_error( "Invalid input: " + error ) { } 26 | }; 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /src/exceptions/ResourceMissing.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef RESOURCE_MISSING_HPP 18 | #define RESOURCE_MISSING_HPP 19 | 20 | #include 21 | 22 | class ResourceMissing : public std::runtime_error{ 23 | public: 24 | ResourceMissing( const std::string& error ) 25 | : std::runtime_error( "Resource missing: " + error ) { } 26 | }; 27 | 28 | #endif 29 | 30 | -------------------------------------------------------------------------------- /styles/_header.scss: -------------------------------------------------------------------------------- 1 | /********** HEADER START **********/ 2 | header nav ul, header nav ul li{ margin:0; padding:0; list-style:none; } 3 | header{ height: 30px; } 4 | header nav{ 5 | position: fixed; 6 | width:100%; 7 | z-index:1; 8 | background-color: black; 9 | padding-top: 5px; 10 | } 11 | 12 | header nav > ul > li{ float: left; } 13 | header nav ul li{ 14 | padding: 0 5px 5px 0; 15 | border-radius:5px; 16 | } 17 | 18 | header > nav li > ul{ 19 | position:absolute; 20 | z-index:1; 21 | background-color: black; 22 | display:none; 23 | border: 2px solid #222; 24 | } 25 | header > nav li:hover > ul{ 26 | display:block; 27 | } 28 | header > nav li > ul > li{ 29 | padding-left: 5px; 30 | } 31 | 32 | /**** search bar ****/ 33 | fieldset{ 34 | margin:0; 35 | padding:0; 36 | border:none; 37 | } 38 | header nav li form{ float:right; } 39 | #search{ 40 | border:none; 41 | background-color:#222; 42 | color:white; 43 | } 44 | #search_list{ 45 | position:absolute; 46 | background-color: black; 47 | } 48 | @media screen and (max-width:380px){ 49 | #search{ 50 | width: 150px; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/objects/Note.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef NOTE_HPP 18 | #define NOTE_HPP 19 | 20 | #include "Identity.hpp" 21 | 22 | #include 23 | 24 | class Note : public Identity<>{ 25 | private: 26 | 27 | 28 | public: 29 | int post_id; 30 | double x; 31 | double y; 32 | double width; 33 | double height; 34 | std::string content; 35 | 36 | Note( unsigned id=0 ) 37 | { this->id = id; } 38 | }; 39 | 40 | #endif 41 | 42 | -------------------------------------------------------------------------------- /src/objects/Identity.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | /* Abstract class, which links to some resource which contents is not known. 18 | * We might have an ID (or list of them), or a boolean determining if any exists 19 | */ 20 | 21 | #ifndef IDENTITY_HPP 22 | #define IDENTITY_HPP 23 | 24 | #include 25 | 26 | template 27 | class Identity{ 28 | public: 29 | typedef identifier ID_T; 30 | identifier id; 31 | }; 32 | 33 | #endif 34 | 35 | -------------------------------------------------------------------------------- /src/pages/TagSearchPage.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef TAG_SEARCH_PAGE_H 18 | #define TAG_SEARCH_PAGE_H 19 | 20 | #include "APage.hpp" 21 | 22 | class TagSearchPage : public StringPage{ 23 | public: 24 | struct Parameters{ 25 | std::string site; 26 | std::string search; 27 | }; 28 | static Parameters parseArguments( Arguments args ); 29 | 30 | std::string serve( Arguments args, std::vector
&headers ) const override; 31 | }; 32 | 33 | #endif 34 | 35 | -------------------------------------------------------------------------------- /src/pages/IndexPage.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef INDEX_PAGE_H 18 | #define INDEX_PAGE_H 19 | 20 | #include "APage.hpp" 21 | 22 | class IndexPage : public StringPage{ 23 | public: 24 | struct Parameters{ 25 | std::string site; 26 | std::string search; 27 | int page; 28 | int limit; 29 | }; 30 | static Parameters parseArguments( Arguments args ); 31 | 32 | std::string serve( Arguments args, std::vector
&headers ) const override; 33 | }; 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /src/server/Server.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef SERVER_H 18 | #define SERVER_H 19 | 20 | #include 21 | 22 | class Server : public Poco::Util::ServerApplication{ 23 | protected: 24 | int main( const std::vector& unknown ); 25 | 26 | public: 27 | static std::string remove_reserved( const std::string& input ); 28 | static std::string encode_str( const std::string& input ); 29 | static std::string unencode_str( const std::string& input ); 30 | }; 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /src/server/ArgsParsing.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef SERVER_H 18 | #define SERVER_H 19 | 20 | #include 21 | 22 | class Server : public Poco::Util::ServerApplication{ 23 | protected: 24 | int main( const std::vector& unknown ); 25 | 26 | public: 27 | static std::string remove_reserved( const std::string& input ); 28 | static std::string encode_str( const std::string& input ); 29 | static std::string unencode_str( const std::string& input ); 30 | }; 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /src/api/ApiHandler.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef API_HANDLER_HPP 18 | #define API_HANDLER_HPP 19 | 20 | #include 21 | #include 22 | 23 | class Api; 24 | 25 | class ApiHandler{ 26 | private: 27 | std::vector apis; 28 | ApiHandler(); 29 | static ApiHandler* instance; 30 | 31 | public: 32 | static ApiHandler* get_instance(); 33 | 34 | std::vector get_apis(){ return apis; } 35 | Api& get_by_shorthand( std::string shorthand ) const; 36 | void flush(); 37 | }; 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /src/objects/Tag.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef TAG_HPP 18 | #define TAG_HPP 19 | 20 | #include "Identity.hpp" 21 | #include 22 | 23 | class Tag : public Identity{ 24 | public: 25 | enum Type{ 26 | NONE, 27 | ARTIST, 28 | COPYRIGHT, 29 | CHARACTER, 30 | SPECIAL, 31 | COMPANY, 32 | UNKNOWN = 255 33 | }; 34 | 35 | public: 36 | Type type{ NONE }; 37 | unsigned count{ 0 }; 38 | 39 | 40 | public: 41 | Tag( std::string id="" ){ this->id = id; } 42 | }; 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /src/db/Database.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of rss2rss. 2 | 3 | rss2rss is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | rss2rss is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with rss2rss. If not, see . 15 | */ 16 | 17 | #ifndef DATABASE_HPP 18 | #define DATABASE_HPP 19 | 20 | #include 21 | 22 | struct sqlite3; 23 | struct sqlite3_stmt; 24 | 25 | class Database{ 26 | private: 27 | sqlite3 *db; 28 | std::string filepath; 29 | 30 | void open(); 31 | 32 | public: 33 | Database( std::string file_path ); 34 | Database( const Database& ) = delete; 35 | ~Database(); 36 | 37 | void reset(); 38 | 39 | operator sqlite3*() const{ return db; } 40 | 41 | int64_t lastRowId(); 42 | }; 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /src/pages/ProxyPage.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef PROXY_PAGE_H 18 | #define PROXY_PAGE_H 19 | 20 | #include "FilePage.hpp" 21 | #include "../objects/Image.hpp" 22 | 23 | class ProxyPage : public FilePage{ 24 | public: 25 | struct Parameters{ 26 | std::string site; 27 | int id; 28 | Image::Size level; 29 | }; 30 | static Parameters parseParameters( Arguments args ); 31 | 32 | Result getImage( class Api& api, const class Post& post, const Image& img ) const; 33 | virtual Result getReader( Arguments args ) const override; 34 | }; 35 | 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /src/objects/Image.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef IMAGE_H 18 | #define IMAGE_H 19 | 20 | #include 21 | 22 | class Image{ 23 | public: 24 | enum Size{ 25 | THUMB 26 | , RESIZED 27 | , COMPRESSED 28 | , ORIGINAL 29 | }; 30 | static Size from_string( std::string input ); 31 | 32 | std::string url; 33 | int width=0; 34 | int height=0; 35 | int size=0; 36 | 37 | bool isLocal() const; 38 | std::string localPath() const; 39 | 40 | void setLocalPath( const std::string& path ) 41 | { url = "file:///" + path; } 42 | }; 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /src/objects/Index.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef INDEX_HPP 18 | #define INDEX_HPP 19 | 20 | #include "Identity.hpp" 21 | #include "Post.hpp" 22 | 23 | #include 24 | #include 25 | 26 | struct IndexId{ 27 | std::string query; 28 | int page; 29 | int limit; 30 | }; 31 | 32 | class Index : public Identity{ 33 | public: 34 | int amount = -1; //Upper bound 35 | //Resource posts{ true }; 36 | std::vector posts; 37 | Resource related_tags{ true }; 38 | 39 | public: 40 | Index( ID_T id ){ this->id = id; } 41 | 42 | }; 43 | 44 | #endif 45 | 46 | -------------------------------------------------------------------------------- /src/api/BehoimiApi.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef BEHOIMI_API_H 18 | #define BEHOIMI_API_H 19 | 20 | #include "DanApi.hpp" 21 | 22 | class BehoimiApi : public DanApi{ 23 | public: 24 | BehoimiApi( std::string short_hand="behoimi" ) : DanApi( short_hand ) { } 25 | 26 | 27 | virtual std::string get_name() const{ return "3dbooru"; } 28 | virtual std::string get_url() const{ return "http://behoimi.org/"; } 29 | 30 | virtual ThemeColor main_color() override{ return {0xFF,0xFF,0xFF}; } 31 | virtual ThemeColor secondary_color() override{ return {0xC3,0xE1,0xFF}; } 32 | }; 33 | 34 | #endif 35 | 36 | -------------------------------------------------------------------------------- /src/pages/png++/NEWS: -------------------------------------------------------------------------------- 1 | Version 0.2.5: 2 | 3 | - Fixed compatibility with newer libpng versions (>= 1.4) 4 | 5 | - Fixed compilation on FreeBSD. 6 | 7 | - Fixed tRNS handling with transformations. 8 | 9 | - Added IO transformation debugging facility. 10 | 11 | - Better organized test suite. 12 | 13 | Version 0.2.3: 14 | 15 | - Fixed numerous `already defined' errors due to require_color_space 16 | implementation. 17 | 18 | - Added `config.hpp'. 19 | 20 | - Fixed `strerror' usage. 21 | 22 | - Minor docs fixes. 23 | 24 | 25 | Version 0.2.1: 26 | 27 | - Added support for tRNS chunk. 28 | 29 | - Added non-std IO streams support. 30 | 31 | - Fixed 16-bit endianness problems. 32 | 33 | - Improved test script. 34 | 35 | 36 | Version 0.2.0: 37 | 38 | - Added support for 16-bit data (RGB, RGBA, Grayscale and Gray+Alpha 39 | color types) 40 | 41 | - Added support for packed 1-, 2- or 4-bit pixels (Grayscale and 42 | Indexed colors) 43 | 44 | - Fixed interlace handling code which was severely broken 45 | 46 | - Added possibility to process images without reading the entire 47 | image into memory 48 | 49 | - Internals are refactored while the client interface is mostly 50 | unchanged 51 | 52 | - Added intensive test suite 53 | 54 | - Added documentation 55 | -------------------------------------------------------------------------------- /src/api/IdolApi.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef IDOL_API_HPP 18 | #define IDOL_API_HPP 19 | 20 | #include "SanApi.hpp" 21 | 22 | class IdolApi : public SanApi{ 23 | public: 24 | IdolApi( std::string short_hand="idol" ) : SanApi( short_hand ) { } 25 | 26 | virtual std::string get_name() const override{ return "IdolComplex"; } 27 | virtual std::string get_url() const override{ return "https://idol.sankakucomplex.com/"; } 28 | 29 | virtual ThemeColor main_color() override{ return {0xFF,0x76,0x1C}; } 30 | virtual ThemeColor secondary_color() override{ return {0xFF,0xFF,0xFF}; } 31 | }; 32 | 33 | #endif 34 | 35 | -------------------------------------------------------------------------------- /src/api/YandereApi.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef YANDERE_API_H 18 | #define YANDERE_API_H 19 | 20 | #include "KonachanApi.hpp" 21 | 22 | class YandereApi : public KonachanApi{ 23 | public: 24 | YandereApi( std::string short_hand="yandere" ) : KonachanApi( short_hand ) { } 25 | 26 | virtual std::string get_name() const override{ return "Yandere"; } 27 | virtual std::string get_url() const override{ return "https://yande.re/"; } 28 | 29 | virtual ThemeColor main_color() override{ return {0xFA,0xB0,0xB1}; } 30 | virtual ThemeColor secondary_color() override{ return {0xFF,0xF3,0xE4}; } 31 | }; 32 | 33 | #endif 34 | 35 | -------------------------------------------------------------------------------- /src/parsing/DataNodeInterface.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef DATA_NODE_INTERFACE_H 18 | #define DATA_NODE_INTERFACE_H 19 | 20 | #include 21 | 22 | class DataNodeInterface{ 23 | public: 24 | virtual bool is_valid( void* p ) const = 0; 25 | 26 | virtual bool as_boolean( void* p ) const = 0; 27 | virtual int as_int( void* p ) const = 0; 28 | virtual std::string as_string( void* p ) const = 0; 29 | 30 | virtual void* get_by_name( void* p, const std::string& child_name ) const = 0; 31 | virtual void* get_by_index( void* p, const int index ) const = 0; 32 | virtual unsigned size( void* p ) const = 0; 33 | }; 34 | 35 | #endif 36 | 37 | -------------------------------------------------------------------------------- /src/api/KonachanApi.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "KonachanApi.hpp" 18 | 19 | const char* const KonachanApi::kona_post_strings[] = { 20 | "id", 21 | "md5", 22 | "author", 23 | "created_at", 24 | "parent_id", 25 | "has_children", 26 | "has_notes", //notes 27 | "has_comments", 28 | NULL, 29 | "source", 30 | "tags", 31 | "score", 32 | "rating", 33 | "status", 34 | 35 | "file_url", 36 | "width", 37 | "height", 38 | "file_size", 39 | 40 | "preview_url", 41 | "preview_width", 42 | "preview_height", 43 | NULL, 44 | 45 | "sample_url", 46 | "sample_width", 47 | "sample_height", 48 | NULL, 49 | 50 | NULL, 51 | NULL, 52 | NULL, 53 | NULL, 54 | }; 55 | 56 | -------------------------------------------------------------------------------- /src/exceptions/utils.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef EXCEPTIONS__UTILS_HPP 18 | #define EXCEPTIONS__UTILS_HPP 19 | 20 | #include "InvalidInput.hpp" 21 | #include 22 | 23 | inline void require( bool valid, const std::string& error ){ 24 | if( !valid ) 25 | throw InvalidInput( error ); 26 | } 27 | 28 | inline int getInt( const std::string& input, const std::string& error="Not an integer" ){ 29 | try{ return stoi( input ); } 30 | catch( ... ){ throw InvalidInput( error ); } 31 | } 32 | 33 | inline void debug( const char* message ) 34 | { std::cout << message; } 35 | 36 | inline void debug( const std::string& message ) 37 | { debug( message.c_str() ); } 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /src/pages/IndexStubPage.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "IndexStubPage.hpp" 18 | #include "IndexPage.hpp" 19 | 20 | #include "../api/Api.hpp" 21 | #include "../api/ApiHandler.hpp" 22 | #include "Styler.hpp" 23 | 24 | using namespace std; 25 | using namespace HTML; 26 | 27 | string IndexStubPage::serve( Arguments args, vector
&headers ) const{ 28 | auto input = IndexPage::parseArguments( args ); 29 | Api& api = ApiHandler::get_instance()->get_by_shorthand( input.site ); 30 | Index index = api.get_index( input.search, input.page, input.limit ); 31 | 32 | headers.push_back( content_type() ); 33 | return Styler( &api, "Index: " + input.search ).post_list( index.posts )(); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/api/LocalApi.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "LocalApi.hpp" 18 | #include "ApiHandler.hpp" 19 | 20 | using namespace std; 21 | 22 | LocalApi::LocalApi( string short_hand ) 23 | : Api( short_hand ) { } 24 | 25 | Post LocalApi::fetch_post( unsigned id, Image::Size level ){ 26 | Post post; 27 | post.id = id; 28 | ApiHandler::get_instance()->get_by_shorthand( site_name ).booru.load( post, level ); 29 | return post; 30 | } 31 | Post LocalApi::get_post( unsigned id, Image::Size level, bool /*force_refresh*/ ) 32 | { return fetch_post( id, level ); } 33 | 34 | Index LocalApi::get_index( string search, int page, int limit ) 35 | { return Booru( site_name ).iteratePosts( { search, page, limit } ); } 36 | -------------------------------------------------------------------------------- /src/pages/HomePage.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "HomePage.hpp" 18 | 19 | #include "../api/Api.hpp" 20 | #include "../api/ApiHandler.hpp" 21 | #include "Styler.hpp" 22 | 23 | using namespace std; 24 | using namespace HTML; 25 | 26 | string HomePage::serve( vector args, vector
&headers ) const{ 27 | vector apis = ApiHandler::get_instance()->get_apis(); 28 | 29 | Styler s( nullptr, "BooruSurfer2" ); 30 | headers.push_back( content_type() ); 31 | 32 | s.body( h1(s.doc)( "Available sites" ) ); 33 | 34 | auto list = ul(s.doc); 35 | for( auto api : apis ) 36 | list( li(s.doc)( a(s.doc, HREF( UrlHandler(api).index_url() ) )( api->get_name() ) ) ); 37 | s.body( list ); 38 | 39 | return s.doc; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /src/pages/NotFoundPage.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "NotFoundPage.hpp" 18 | 19 | #include "Styler.hpp" 20 | 21 | #include 22 | 23 | using namespace std; 24 | using namespace HTML; 25 | 26 | string NotFoundPage::serve( vector args, vector
&headers ) const{ 27 | //Rebuild the query, as it was split apart 28 | auto add_dir = [](string sum, string add){ return ( add != ".." ) ? sum + "/" + add : ""; }; 29 | string query = accumulate( args.begin(), args.end(), string(""), add_dir ); 30 | 31 | //TODO: set error code 32 | Styler s( nullptr, "Could not find \'" + query + "'" ); 33 | headers.push_back( content_type() ); 34 | 35 | s.container( h3( s.doc )( "404: Page not found" ) ); 36 | s.container( p( s.doc )( query ) ); 37 | 38 | return s.doc; 39 | } 40 | 41 | -------------------------------------------------------------------------------- /src/pages/PageHandler.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef PAGE_HANDLER_H 18 | #define PAGE_HANDLER_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | class APage; 27 | 28 | class PageHandler{ 29 | private: 30 | typedef std::unique_ptr APage_ptr; 31 | std::unordered_map pages; 32 | APage_ptr page_root; 33 | APage_ptr page_404; 34 | 35 | public: 36 | PageHandler(); 37 | ~PageHandler(); 38 | 39 | template 40 | void add( std::string name ){ //TODO: support arguments to constructor 41 | pages[ name ] = std::make_unique(); 42 | } 43 | 44 | APage* get( std::string page ); 45 | APage* get_root(){ return page_root.get(); } 46 | }; 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /src/pages/png++/COPYING: -------------------------------------------------------------------------------- 1 | Copying png++ is subject to the following license: 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | 1. Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | 3. The name of the author may not be used to endorse or promote products 14 | derived from this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 | WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 | EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 22 | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 23 | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 | POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /src/objects/Image.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "Image.hpp" 18 | #include "../exceptions/utils.hpp" 19 | 20 | #include 21 | 22 | constexpr const char* URL_FILE = "file:///"; 23 | constexpr int URL_FILE_LENGHT = std::strlen( URL_FILE ); 24 | 25 | Image::Size Image::from_string( std::string input ){ 26 | if( input == "thumb" ) return THUMB; 27 | if( input == "resized" ) return RESIZED; 28 | if( input == "compressed" ) return COMPRESSED; 29 | return ORIGINAL; 30 | } 31 | 32 | bool Image::isLocal() const{ 33 | if( url.empty() ) 34 | return false; 35 | return url.compare( 0, URL_FILE_LENGHT, URL_FILE ) == 0; //TODO: Use starts_with 36 | } 37 | 38 | std::string Image::localPath() const{ 39 | require( isLocal(), "Must be a file url: " + url ); 40 | return url.substr( URL_FILE_LENGHT ); 41 | } 42 | 43 | -------------------------------------------------------------------------------- /src/parsing/NullDataNode.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef NULL_DATA_NODE_H 18 | #define NULL_DATA_NODE_H 19 | 20 | #include "DataNodeInterface.hpp" 21 | #include 22 | 23 | class NullDataNode : public DataNodeInterface{ 24 | public: 25 | static DataNodeInterface* get_instance(){ 26 | static NullDataNode* instance = NULL; 27 | return instance ? instance : instance = new NullDataNode(); 28 | } 29 | 30 | virtual bool is_valid( void* p ) const{ return false; } 31 | 32 | virtual bool as_boolean( void* p ) const{ return false; } 33 | virtual int as_int( void* p ) const{ return 0; } 34 | virtual std::string as_string( void* p ) const{ return ""; } 35 | 36 | virtual void* get_by_name( void* p, const std::string& child_name ) const{ return NULL; } 37 | virtual void* get_by_index( void* p, const int index ) const{ return NULL; } 38 | virtual unsigned size( void* p ) const{ return 0; } 39 | }; 40 | 41 | #endif 42 | 43 | -------------------------------------------------------------------------------- /src/system/TimeHandling.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "TimeHandling.hpp" 18 | 19 | //TODO: Remove dependency on Poco 20 | #include 21 | #include 22 | #include 23 | 24 | 25 | Time Time::FromSimpleFormat( std::string_view formatted_string ){ 26 | Poco::DateTime datetime; 27 | int timezone; 28 | 29 | Poco::DateTimeParser::parse( Poco::DateTimeFormat::SORTABLE_FORMAT, std::string(formatted_string), datetime, timezone ); 30 | return { datetime.timestamp().epochTime() }; 31 | } 32 | 33 | std::string Time::formatSimple() const{ 34 | auto poco_time = Poco::Timestamp::fromEpochTime( value ); 35 | return Poco::DateTimeFormatter::format( poco_time, "%Y-%m-%d %H:%M" ); 36 | } 37 | 38 | std::string Time::formatRFC822() const{ 39 | auto poco_time = Poco::Timestamp::fromEpochTime( value ); 40 | return Poco::DateTimeFormatter::format( poco_time, Poco::DateTimeFormat::RFC1123_FORMAT ); 41 | } 42 | -------------------------------------------------------------------------------- /src/objects/Resource.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | /* Abstract class, which links to some resource which contents is not known. 18 | * We might have an ID (or list of them), or a boolean determining if any exists 19 | */ 20 | 21 | #ifndef RESOURCE_HPP 22 | #define RESOURCE_HPP 23 | 24 | #include 25 | #include 26 | 27 | template 28 | class Resource{ 29 | public: 30 | typedef identity Object; 31 | std::vector list; 32 | bool exists = true; //If true, content might exist even if list is empty 33 | 34 | Resource(){ } 35 | Resource( bool exists ) : exists(exists){ } 36 | Resource( std::vector list ) : list(list){ } 37 | 38 | bool contains(typename identity::ID_T id ) const 39 | { return std::find( list.begin(), list.end(), id ) != list.end(); } 40 | 41 | void add( typename identity::ID_T id ){ 42 | list.push_back( id ); 43 | } 44 | }; 45 | 46 | #endif 47 | 48 | -------------------------------------------------------------------------------- /src/db/Database.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of rss2rss. 2 | 3 | rss2rss is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | rss2rss is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with rss2rss. If not, see . 15 | */ 16 | 17 | #include "Database.hpp" 18 | 19 | #include "Statement.hpp" 20 | 21 | #include 22 | 23 | #include 24 | #include 25 | 26 | using namespace std; 27 | 28 | void Database::open(){ 29 | auto flags = SQLITE_OPEN_READWRITE | SQLITE_CONFIG_MULTITHREAD; 30 | if( sqlite3_open_v2( filepath.c_str(), &db, flags, nullptr ) != SQLITE_OK ){ 31 | //TODO: throw exception 32 | cout << "Couldn't open db! Path: " << filepath.c_str() << '\n'; 33 | sqlite3_close( db ); 34 | exit( -1 ); 35 | } 36 | sqlite3_busy_timeout( db, 100 ); 37 | Statement( *this, "PRAGMA journal_mode=WAL;" ).next(); 38 | } 39 | 40 | Database::Database( string filepath ) : filepath(filepath) { open(); } 41 | 42 | Database::~Database(){ 43 | // cout << "Destroying" << '\n'; 44 | sqlite3_close( db ); 45 | } 46 | 47 | void Database::reset(){ 48 | sqlite3_close( db ); 49 | open(); 50 | } 51 | 52 | int64_t Database::lastRowId(){ 53 | return sqlite3_last_insert_rowid( db ); 54 | } 55 | -------------------------------------------------------------------------------- /src/system/TimeHandling.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef TIME_HANDLING_HPP 18 | #define TIME_HANDLING_HPP 19 | 20 | #include 21 | 22 | struct Time{ 23 | private: 24 | int64_t value{ 0 }; 25 | 26 | Time( int64_t value ) : value(value) { } 27 | 28 | public: 29 | Time() = default; 30 | 31 | //Construct a time from a 'YYYY-MM-DD hh:mm:ss' formatted string 32 | static Time FromSimpleFormat( std::string_view formatted_string ); 33 | 34 | ///Construct a time from a Unix time 35 | static Time FromUnixTime( int64_t time ){ return { time }; } 36 | 37 | int64_t toUnixTime() const{ return value; } 38 | 39 | bool isValid() const{ return value != 0; } 40 | 41 | std::string formatSimple() const; 42 | std::string formatRFC822() const; 43 | 44 | bool operator<( Time other ) const{ return value < other.value; } 45 | 46 | void addSeconds( int64_t seconds ){ value += seconds; } 47 | }; 48 | 49 | std::string get_thumbnail( std::string path ); 50 | 51 | #endif 52 | 53 | -------------------------------------------------------------------------------- /src/api/LocalApi.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef LOCAL_API_H 18 | #define LOCAL_API_H 19 | 20 | #include "Api.hpp" 21 | 22 | #include 23 | #include 24 | 25 | class LocalApi : public Api{ 26 | public: 27 | LocalApi( std::string short_hand ); 28 | 29 | std::string get_name() const override{ return "Local files"; } 30 | std::string get_shorthand() const override{ return "local-" + site_name; } 31 | std::string get_url() const override{ return "file:///"; } 32 | 33 | Post fetch_post( unsigned id, Image::Size level ) override; 34 | Post get_post( unsigned id, Image::Size level, bool force_refresh ) override; 35 | Index get_index( std::string search, int page, int limit=-1 ) override; 36 | 37 | ThemeColor main_color() override{ return {0xA4,0x81,0x5E}; } 38 | ThemeColor secondary_color() override{ return {0xFF,0xFF,0xFF}; } 39 | 40 | std::string original_post_url( unsigned id ) override{ return {}; } 41 | std::string original_index_url( std::string search ) override{ return {}; } 42 | }; 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /src/api/SanApi.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef SAN_API_H 18 | #define SAN_API_H 19 | 20 | #include "Api.hpp" 21 | #include "../server/Server.hpp" 22 | 23 | class SanApi : public Api{ 24 | public: 25 | SanApi( std::string short_hand="san" ) : Api( short_hand ) { } 26 | 27 | std::string get_name() const override{ return "Sankaku-chan"; } 28 | std::string get_url() const override{ return "https://chan.sankakucomplex.com/"; } 29 | 30 | 31 | Post fetch_post( unsigned id, Image::Size level ) override; 32 | Index get_index( std::string search, int page, int limit=-1 ) override; 33 | 34 | ThemeColor main_color() override{ return {0xFF,0xFF,0xFF}; } 35 | ThemeColor secondary_color() override{ return {0xFF,0x76,0x1C}; } 36 | 37 | std::string original_post_url( unsigned id ) override{ 38 | return get_url() + "post/show/" + std::to_string( id ); 39 | } 40 | std::string original_index_url( std::string search ) override{ 41 | return get_url() + "?tags=" + Server::remove_reserved( Server::encode_str( search ) ); 42 | } 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /src/pages/UrlHandler.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef URL_HANDLER_H 18 | #define URL_HANDLER_H 19 | 20 | #include "../objects/Post.hpp" 21 | #include 22 | #include 23 | 24 | class Api; 25 | 26 | class UrlHandler{ 27 | private: 28 | Api* api; 29 | 30 | std::string search_url( std::string type, const std::vector& tags, unsigned page, int amount ) const; 31 | 32 | public: 33 | UrlHandler( Api* api ) : api(api) { } 34 | 35 | std::string post_url( const Post& p ) const; 36 | 37 | std::string index_url( const std::vector& tags = std::vector(), unsigned page=1, int amount = -1 ) const 38 | { return search_url( "index", tags, page, amount ); } 39 | 40 | std::string rss_url( const std::vector& tags = std::vector(), unsigned page=1, int amount = -1 ) const 41 | { return search_url( "rss", tags, page, amount ); } 42 | 43 | std::string image_tags( const Post& p, int lenght ); 44 | 45 | std::string image_url( const Post& p, Image::Size size, bool save=false ); 46 | }; 47 | 48 | #endif 49 | 50 | -------------------------------------------------------------------------------- /src/pages/TagSearchPage.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "TagSearchPage.hpp" 18 | 19 | #include "../api/Api.hpp" 20 | #include "../api/ApiHandler.hpp" 21 | #include "../exceptions/utils.hpp" 22 | 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | using namespace std; 29 | 30 | TagSearchPage::Parameters TagSearchPage::parseArguments( Arguments args ){ 31 | require( args.size() >= 2, "Incorrect arguments" ); 32 | return { args[1], args.size() == 3 ? args[2] : std::string() }; 33 | } 34 | 35 | string TagSearchPage::serve( vector args, vector
&headers ) const{ 36 | auto input = parseArguments( args ); 37 | Api& api = ApiHandler::get_instance()->get_by_shorthand( input.site ); 38 | 39 | if (input.search.empty()) 40 | return "[]"; 41 | 42 | auto tags = api.booru.searchTags( input.search ); 43 | 44 | nlohmann::json j; 45 | for(auto tag : tags) 46 | j.push_back( { 47 | {"id", tag.id}, 48 | {"count", tag.count}, 49 | {"type", (int)tag.type} 50 | } ); 51 | 52 | return j.dump(); 53 | } 54 | 55 | -------------------------------------------------------------------------------- /src/api/KonachanApi.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef KONACHAN_API_H 18 | #define KONACHAN_API_H 19 | 20 | #include "DanApi.hpp" 21 | 22 | class KonachanApi : public DanApi{ 23 | protected: 24 | static const char* const kona_post_strings[POST_ITEM_SIZE]; 25 | 26 | public: 27 | KonachanApi( std::string short_hand="kona" ) : DanApi( short_hand ) { } 28 | 29 | virtual std::string get_name() const override{ return "Konachan"; } 30 | virtual std::string get_url() const override{ return "http://konachan.com/"; } 31 | 32 | const char* const* post_table() const{ return kona_post_strings; } 33 | 34 | virtual ThemeColor main_color() override{ return {0x71,0x57,0x5A}; } 35 | virtual ThemeColor secondary_color() override{ return {0xFF,0xEC,0xCE}; } 36 | 37 | virtual std::string original_post_url( unsigned id ) override{ 38 | return get_url() + "post/show/" + std::to_string( id ) + "/"; 39 | } 40 | virtual std::string original_index_url( std::string search ) override{ 41 | return get_url() + "post/?tags=" + search; 42 | } 43 | }; 44 | 45 | #endif 46 | 47 | -------------------------------------------------------------------------------- /src/db/LocalDb.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef LOCAL_DB_HPP 18 | #define LOCAL_DB_HPP 19 | 20 | #include "Database.hpp" 21 | #include "Statement.hpp" 22 | 23 | #include 24 | 25 | class DbIndex{ 26 | private: 27 | int64_t id{ -1 }; //Negative values means invalid index 28 | 29 | public: 30 | DbIndex( int64_t id=-1 ) : id(id) {} 31 | 32 | int64_t get() const{ return id; } 33 | //TODO: debug exception on invalid index? 34 | //Or use the maybe scheme instead? We may want to pass an invalid index though 35 | 36 | operator bool() const{ return id >= 0; } 37 | operator int64_t() const{ return get(); } 38 | }; 39 | 40 | class LocalDb{ 41 | private: 42 | Database db; 43 | 44 | void addFolderToDbInternal( const std::string& folder_path, int64_t& counter ); 45 | 46 | public: 47 | LocalDb(); 48 | 49 | static std::string sanitizeFolderPath( std::string path ); 50 | DbIndex getFolderId( const std::string& folder_path ); 51 | 52 | DbIndex addMedia( DbIndex path_id, const std::string& file_name ); //TODO: Much more 53 | 54 | void addFolderToDb( const std::string& folder_path ); 55 | }; 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /src/pages/PageHandler.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "PageHandler.hpp" 18 | 19 | #include "APage.hpp" 20 | #include "HomePage.hpp" 21 | #include "PostPage.hpp" 22 | #include "IndexPage.hpp" 23 | #include "IndexStubPage.hpp" 24 | #include "FilePage.hpp" 25 | #include "OpenSearchPage.hpp" 26 | #include "ProxyPage.hpp" 27 | #include "SavePage.hpp" 28 | #include "NotFoundPage.hpp" 29 | #include "FaviconPage.hpp" 30 | #include "RssPage.hpp" 31 | #include "TagSearchPage.hpp" 32 | 33 | PageHandler::PageHandler() 34 | : page_root( new HomePage() ) 35 | , page_404( new NotFoundPage() ) 36 | { 37 | add( "index" ); 38 | add( "jsindex" ); 39 | add( "post" ); 40 | add( "file" ); 41 | add( "proxy" ); 42 | add( "save" ); 43 | add( "favicon" ); 44 | add( "rss" ); 45 | add( "search" ); 46 | add( "tags" ); 47 | } 48 | 49 | 50 | PageHandler::~PageHandler(){ 51 | 52 | } 53 | 54 | 55 | APage* PageHandler::get( std::string page ){ 56 | auto got = pages.find( page ); 57 | if( got != pages.end() ) 58 | return got->second.get(); 59 | else 60 | return page_404.get(); 61 | } 62 | 63 | -------------------------------------------------------------------------------- /src/pages/FilePage.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef FILE_PAGE_H 18 | #define FILE_PAGE_H 19 | 20 | #include "APage.hpp" 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | class FilePage : public StreamPage{ 28 | private: 29 | std::unordered_map mimes; 30 | 31 | public: 32 | class StreamReader : public Reader{ 33 | private: 34 | std::istream& stream; 35 | 36 | public: 37 | StreamReader( std::istream& stream ) : stream(stream) { } 38 | unsigned readBuf( char* buf, unsigned size ) override{ 39 | stream.read( buf, size ); 40 | return stream.gcount(); 41 | } 42 | }; 43 | 44 | struct FileReader : public StreamReader{ 45 | std::fstream fs; 46 | FileReader( std::string path ); 47 | }; 48 | 49 | struct StringReader : public StreamReader{ 50 | std::istringstream is; 51 | StringReader( const std::string& contents ); 52 | }; 53 | 54 | public: 55 | using Result = std::pair, std::string>; 56 | FilePage(); 57 | virtual Result getReader( Arguments args ) const; 58 | virtual std::unique_ptr serve( Arguments args, std::vector
& headers ) const final; 59 | std::string get_mime( std::string ext ) const; 60 | }; 61 | 62 | #endif 63 | 64 | -------------------------------------------------------------------------------- /premake4.lua: -------------------------------------------------------------------------------- 1 | solution( "BooruSurfer2" ) 2 | configurations{ "debug", "release" } 3 | 4 | project( "Server" ) 5 | kind( "ConsoleApp" ) 6 | targetname( "BooruSurfer" ) 7 | language( "C++" ) 8 | location( "build" ) 9 | files( { "./src/**.h", "./src/**.cpp" } ) 10 | 11 | -- Enable C++14 support 12 | buildoptions{ "-std=c++14 -pthread" } 13 | 14 | -- Warnings 15 | buildoptions{ "-Wall" } 16 | 17 | links( { 18 | "tidy" 19 | , "jansson" 20 | , "png" 21 | , "sqlite3" 22 | 23 | -- Poco libraries and dependencies 24 | , "PocoNetSSL" 25 | , "PocoCrypto" 26 | , "PocoNet" 27 | , "PocoUtil" 28 | , "PocoJSON" 29 | , "PocoXML" 30 | , "PocoFoundation" 31 | , "Ws2_32" 32 | , "wsock32" 33 | , "ssl" 34 | , "crypto" 35 | , "iphlpapi" 36 | 37 | -- Windows thumbnail 38 | , "Shell32" 39 | , "Uuid" 40 | , "Gdi32" 41 | , "Ole32" 42 | , "Windowscodecs" 43 | , "boost_system-mgw52-mt-1_61" 44 | , "boost_filesystem-mgw52-mt-1_61.dll" 45 | } ) 46 | 47 | defines { "POCO_STATIC" } 48 | 49 | configuration( "debug" ) 50 | build_dir = "debug" 51 | targetdir( "bin/" .. build_dir ) 52 | defines( { "DEBUG" } ) 53 | flags { "Symbols" } 54 | 55 | configuration( "release" ) 56 | build_dir = "release" 57 | targetdir( "bin/" .. build_dir ) 58 | defines( { "RELEASE" } ) 59 | flags { "Optimize" } 60 | 61 | 62 | -- Copy data files 63 | os.mkdir( "bin/" .. build_dir .. "/data" ) 64 | files = os.matchfiles( "data/*.*" ); 65 | for k, f in pairs( files ) do 66 | os.copyfile( f, "bin/" .. build_dir .. "/data/" .. path.getname(f) ); 67 | end 68 | 69 | -- Copy resource files 70 | os.mkdir( "bin/" .. build_dir .. "/data" ) 71 | files = os.matchfiles( "resources/*.*" ); 72 | for k, f in pairs( files ) do 73 | os.copyfile( f, "bin/" .. build_dir .. "/resources/" .. path.getname(f) ); 74 | end 75 | 76 | --Compile Scss 77 | os.execute( "sass styles/main.scss bin/" .. build_dir .. "/resources/main.css" ); 78 | -------------------------------------------------------------------------------- /src/api/ApiHandler.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | 18 | #include "ApiHandler.hpp" 19 | #include "../exceptions/InvalidInput.hpp" 20 | #include "../db/AddLocal.hpp" 21 | 22 | #include "IdolApi.hpp" 23 | #include "YandereApi.hpp" 24 | #include "BehoimiApi.hpp" 25 | #include "ShimmieApi.hpp" 26 | #include "LocalApi.hpp" 27 | 28 | ApiHandler* ApiHandler::instance{ nullptr }; 29 | 30 | ApiHandler::ApiHandler() : apis{ 31 | //TODO: add all the apis 32 | //TODO: cleanup 33 | new DanApi() 34 | , new SanApi() 35 | , new IdolApi() 36 | , new KonachanApi() 37 | , new YandereApi() 38 | , new BehoimiApi() 39 | , new Rule34Api() 40 | , new LocalApi( "san" ) 41 | }{ 42 | //TODO: avoid this shit 43 | // ((DanApi*)get_by_shorthand( "kona" ))->load_tag_file(); 44 | // ((DanApi*)get_by_shorthand( "yandere" ))->load_tag_file(); 45 | } 46 | 47 | ApiHandler* ApiHandler::get_instance(){ 48 | //TODO: make atomic 49 | if( !instance ){ 50 | instance = new ApiHandler; 51 | // addFolder( "out/" ); 52 | } 53 | return instance; 54 | } 55 | 56 | Api& ApiHandler::get_by_shorthand( std::string shorthand ) const{ 57 | for( auto api : apis ) 58 | if( api->get_shorthand() == shorthand ) 59 | return *api; 60 | throw InvalidInput( shorthand + " is not a site" ); 61 | } 62 | 63 | void ApiHandler::flush(){ 64 | for( auto api : apis ) 65 | api->flush(); 66 | } 67 | -------------------------------------------------------------------------------- /src/system/Thumbnailer-kde.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifdef LINUX 18 | 19 | #include "Thumbnailer.hpp" 20 | 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | std::string get_thumbnail( std::string path ){ 33 | using namespace KIO; 34 | 35 | //Initialize job 36 | auto url = QUrl::fromLocalFile( QFileInfo(QString::fromLocal8Bit( path.c_str() )).absoluteFilePath() ); 37 | KFileItem file( url ); 38 | auto list = QList() << file; 39 | KIO::PreviewJob job( list, QSize( 512, 512 ) ); 40 | job.setIgnoreMaximumSize( true ); 41 | 42 | //Set thumb getter 43 | QEventLoop loop; 44 | QByteArray array; 45 | QBuffer buffer( &array ); 46 | 47 | QObject::connect( &job, &KIO::PreviewJob::gotPreview, [&](const KFileItem&, const QPixmap& result){ 48 | //convert pixmap to BMP 49 | result.save( &buffer, "BMP" ); //TODO: transparency? 50 | loop.quit(); 51 | } ); 52 | QObject::connect( &job, &KIO::PreviewJob::failed, [&](const KFileItem&){ 53 | loop.quit(); 54 | } ); 55 | 56 | //Wait for thumbnail to finish processing 57 | job.start(); 58 | loop.exec(); 59 | 60 | return std::string( array.constData(), array.size() ); 61 | } 62 | 63 | 64 | #endif 65 | 66 | -------------------------------------------------------------------------------- /src/pages/OpenSearchPage.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "OpenSearchPage.hpp" 18 | 19 | #include 20 | 21 | #include "../api/Api.hpp" 22 | #include "../api/ApiHandler.hpp" 23 | #include "../exceptions/utils.hpp" 24 | #include "../parsing/OpenSearchDescription.hpp" 25 | #include "UrlHandler.hpp" 26 | 27 | using namespace std; 28 | 29 | string OpenSearchPage::serve( vector args, vector
&headers ) const{ 30 | require( args.size() >= 2, "Too few arguments" ); 31 | Api& api = ApiHandler::get_instance()->get_by_shorthand( args[1] ); 32 | UrlHandler url( &api ); 33 | 34 | string search = ""; 35 | if( args.size() == 3 ) 36 | search = args[2]; 37 | 38 | OpenSearchDescription osd; 39 | osd.short_name = "Booru: " + api.get_shorthand(); 40 | osd.long_name = api.get_name(); 41 | osd.description = "Search " + api.get_name() + " for images"; 42 | osd.input_encoding = "UTF-8"; 43 | //TODO: image 44 | osd.adult_content = false; 45 | 46 | OpenSearchDescription::Url search_url; 47 | //TODO: get absolute name 48 | search_url.temp = "http://localhost:8000/index/" + args[1] + "/{searchTerms}"; 49 | search_url.type = "text/html"; 50 | // search_url.rel = "results"; 51 | osd.urls.push_back( search_url ); 52 | 53 | //headers.push_back( header( "Content-Type", "application/opensearchdescription+xml" ) ); 54 | return osd.save(); 55 | } 56 | 57 | -------------------------------------------------------------------------------- /src/pages/APage.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef A_PAGE_H 18 | #define A_PAGE_H 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | namespace Poco{ 26 | namespace Net{ 27 | class HTTPServerResponse; 28 | } 29 | } 30 | 31 | class APage{ 32 | public: 33 | using header = std::pair; 34 | using Arguments = std::vector; 35 | static header content_type( std::string mime="text/html; charset=utf-8" ){ return header( "Content-Type", mime ); } 36 | virtual void handleRequest( Arguments args, Poco::Net::HTTPServerResponse& response ) = 0; 37 | virtual ~APage(){ } 38 | }; 39 | 40 | class StringPage : public APage{ 41 | public: 42 | virtual std::string serve( Arguments args, std::vector
&headers ) const = 0; 43 | virtual void handleRequest( Arguments args, Poco::Net::HTTPServerResponse& response ) override; 44 | }; 45 | 46 | class StreamPage: public APage{ 47 | public: 48 | struct Reader{ 49 | virtual unsigned readBuf( char* buf, unsigned size ) = 0; 50 | virtual ~Reader(){ } 51 | 52 | void writeAll( std::ostream& out ); 53 | }; 54 | 55 | virtual std::unique_ptr serve( Arguments args, std::vector
& headers ) const = 0; 56 | virtual void handleRequest( Arguments args, Poco::Net::HTTPServerResponse& response ) final; 57 | }; 58 | 59 | #endif 60 | 61 | -------------------------------------------------------------------------------- /src/pages/png++/palette.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007,2008 Alex Shulgin 3 | * 4 | * This file is part of png++ the C++ wrapper for libpng. PNG++ is free 5 | * software; the exact copying conditions are as follows: 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 23 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 25 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef PNGPP_PALETTE_HPP_INCLUDED 32 | #define PNGPP_PALETTE_HPP_INCLUDED 33 | 34 | #include 35 | #include "color.hpp" 36 | 37 | namespace png 38 | { 39 | 40 | /** 41 | * \brief The palette type. Currently implemented as \c std::vector 42 | * of png::color. 43 | */ 44 | typedef std::vector< color > palette; 45 | 46 | } // namespace png 47 | 48 | #endif // PNGPP_PALETTE_HPP_INCLUDED 49 | -------------------------------------------------------------------------------- /src/pages/png++/tRNS.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007,2008 Alex Shulgin 3 | * 4 | * This file is part of png++ the C++ wrapper for libpng. PNG++ is free 5 | * software; the exact copying conditions are as follows: 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 23 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 25 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef PNGPP_TRNS_HPP_INCLUDED 32 | #define PNGPP_TRNS_HPP_INCLUDED 33 | 34 | #include 35 | #include "color.hpp" 36 | 37 | namespace png 38 | { 39 | 40 | /** 41 | * \brief The palette transparency map type. Currently 42 | * implemented as \c std::vector of png::byte. 43 | */ 44 | typedef std::vector< byte > tRNS; 45 | 46 | } // namespace png 47 | 48 | #endif // PNGPP_TRNS_HPP_INCLUDED 49 | -------------------------------------------------------------------------------- /src/objects/ResourceHandler.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | /* Abstract class, which links to some resource which contents is not known. 18 | * We might have an ID (or list of them), or a boolean determining if any exists 19 | */ 20 | 21 | #ifndef RESOURCE_HANDLER_HPP 22 | #define RESOURCE_HANDLER_HPP 23 | 24 | #include "../db/Booru.hpp" 25 | #include "Resource.hpp" 26 | 27 | template 28 | class ResourceHandler{ 29 | private: 30 | Booru& booru; 31 | 32 | public: 33 | ResourceHandler( Booru& booru ) : booru(booru) { } 34 | void add( object& obj ){ booru.save( obj ); } 35 | 36 | template 37 | void addAll( Iter begin, Iter end, Func f ){ 38 | for( auto start=begin; start!=end; ++start ){ 39 | auto obj = f( *start ); 40 | booru.save( obj ); 41 | } 42 | } 43 | 44 | template 45 | object get( indentifier id, Args... args ) const{ 46 | object temp( id ); 47 | return booru.load( temp, args... ) ? temp : object( id ); 48 | } 49 | 50 | std::vector getAll( const Resource& resource ){ 51 | std::vector list; 52 | list.reserve( resource.list.size() ); 53 | 54 | for( auto id : resource.list ) 55 | list.emplace_back( get( id ) ); 56 | 57 | return list; 58 | } 59 | 60 | template 61 | bool get_checked( indentifier id, object& obj, Args... args ){ 62 | obj.id = id; 63 | return booru.load( obj, args... ); 64 | } 65 | }; 66 | 67 | #endif 68 | 69 | -------------------------------------------------------------------------------- /src/api/ShimmieApi.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef SHIMMIE_API_H 18 | #define SHIMMIE_API_H 19 | 20 | #include "Api.hpp" 21 | #include "../server/Server.hpp" 22 | 23 | class ShimmieApi : public Api{ 24 | protected: 25 | 26 | 27 | public: 28 | ShimmieApi( std::string short_hand="shimmie" ) : Api( short_hand ) { } 29 | 30 | virtual std::string get_name() const{ return "Shimmie Testbed"; } 31 | virtual std::string get_url() const{ return "http://shimmie.shishnet.org/v2/"; } 32 | 33 | 34 | Post fetch_post( unsigned id, Image::Size level ); 35 | Index get_index( std::string search, int page, int limit=-1 ); 36 | 37 | virtual ThemeColor main_color() override{ return {0xFF,0xFF,0xFF}; } 38 | virtual ThemeColor secondary_color() override{ return {0xFF,0x76,0x1C}; } 39 | 40 | virtual std::string original_post_url( unsigned id ) override{ 41 | return get_url() + "post/view/" + std::to_string( id ); 42 | } 43 | virtual std::string original_index_url( std::string search ) override{ 44 | return get_url() + "post/list/" + Server::remove_reserved( Server::encode_str( search ) ); 45 | } 46 | }; 47 | 48 | class Rule34Api : public ShimmieApi{ 49 | public: 50 | Rule34Api() : ShimmieApi( "rule34" ) { } 51 | 52 | std::string get_name() const override{ return "Rule 34"; } 53 | std::string get_url() const override{ return "http://rule34.paheal.net/"; } 54 | 55 | ThemeColor main_color() override{ return {0x00,0x43,0x08}; } 56 | ThemeColor secondary_color() override{ return {0xAC,0xE4,0xA3}; } 57 | }; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /resources/infinity.js: -------------------------------------------------------------------------------- 1 | var items = window.location.pathname.split("/") 2 | items.shift() 3 | 4 | var strictParseInt = function( str ) { 5 | if( isNaN( String( str ) * 1 ) ) 6 | return NaN 7 | return parseInt( str ); 8 | } 9 | 10 | var site = items[1]; 11 | var page_parsed = strictParseInt( items[2] ); 12 | var page = isNaN(page_parsed) ? 1 : page_parsed; 13 | var limit = -1; //TODO: implement 14 | var search = isNaN(page_parsed) ? items[2] : items[3]; 15 | 16 | var index_url = function() { return "/jsindex/" + site + "/" + (page+1) + "/" + search; } 17 | 18 | var load_next = function() { 19 | // alert( "loading next" ); 20 | $.get( index_url(), function( response ){ 21 | $( "#container .post_list" ).append( response ); 22 | page += 1; 23 | }); 24 | } 25 | 26 | window.onload = function() { 27 | 28 | $.get( index_url(), function( response ) { 29 | $( "nav.page_nav" ).remove(); 30 | $( "#container .post_list" ).append( response ); 31 | page += 1; 32 | 33 | $(window).scroll(function(){ 34 | var current = $(window).scrollTop() + window.innerHeight; 35 | var total = $(document).height(); 36 | if(Math.round(current) >= total) { 37 | load_next(); 38 | } 39 | }); 40 | } ); 41 | 42 | $("#search").parent().append('
'); 43 | $("#search").attr("autocomplete", "off"); 44 | 45 | $("#search").on("input", function(){ 46 | var value = $("#search").val(); 47 | $.getJSON( "/tags/" + site + "/" + value, function(data){ 48 | var ul = $("
", {id: "search_list"}); 49 | 50 | data.forEach(function(item){ 51 | var name = item["id"]; 52 | var li = $('
  • ') 53 | var add = $('', {"href":"/index/" + site + "/" + search + "+" + name}); 54 | add.append("+"); 55 | var sub = $('', {"href":"/index/" + site + "/" + search + "+-" + name}); 56 | sub.append("-"); 57 | var a = $('', {"class": "tagtype" + item['type'], "href":"/index/" + site + "/" + name}); 58 | var span = $('(' + item['count'] + ')'); 59 | a.append(name); 60 | a.append(span); 61 | li.append(add); 62 | li.append(sub); 63 | li.append(a); 64 | ul.append(li); 65 | }); 66 | $("#search_list").replaceWith(ul); 67 | } ); 68 | }); 69 | } 70 | -------------------------------------------------------------------------------- /src/objects/Post.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef POST_H 18 | #define POST_H 19 | 20 | #include "../system/TimeHandling.hpp" 21 | 22 | #include "Tag.hpp" 23 | #include "Image.hpp" 24 | #include "Resource.hpp" 25 | #include "Identity.hpp" 26 | #include "Note.hpp" 27 | #include "Comment.hpp" 28 | #include "Pool.hpp" 29 | 30 | #include 31 | #include 32 | 33 | class Post : public Identity<>{ 34 | public: 35 | enum Rating{ 36 | SAFE, 37 | QUESTIONABLE, 38 | EXPLICIT, 39 | UNRATED = 255 40 | }; 41 | 42 | enum Status{ 43 | NORMAL, 44 | PENDING, 45 | FLAGGED 46 | }; 47 | 48 | public: 49 | Post(){ id = 0; } 50 | Post( ID_T id ){ this->id = id; } 51 | 52 | std::string hash; 53 | std::string author; 54 | Time creation_time; 55 | 56 | 57 | Resource tags; 58 | Resource parents; 59 | Resource children; 60 | Resource notes; 61 | Resource comments; 62 | Resource pools; 63 | 64 | std::string source; 65 | 66 | int score = 0; 67 | Rating rating = UNRATED; 68 | 69 | bool saved{ false }; 70 | 71 | Image full; 72 | Image reduced; 73 | Image preview; 74 | Image thumbnail; 75 | 76 | Image get_image_size( Image::Size size ) const; 77 | bool isAvailable( Image::Size size ) const; 78 | 79 | 80 | public: 81 | unsigned get_id() const{ return id; } 82 | std::string get_hash() const{ return hash; } 83 | std::string get_author() const{ return author; } 84 | 85 | Post combine( const Post& other ) const; 86 | }; 87 | 88 | #endif 89 | 90 | -------------------------------------------------------------------------------- /src/pages/png++/INSTALL: -------------------------------------------------------------------------------- 1 | General 2 | ======= 3 | 4 | PNG++ comes as a set of header files and does not require compilation 5 | to be installed. For the same reason there are no binary packages for 6 | png++. 7 | 8 | 9 | Prerequisites 10 | ============= 11 | 12 | - png++ is known to work with libpng-1.2.x (probably, the 1.4.x 13 | flavour will work too) 14 | 15 | - png++ compiles with g++-4.1. Other version should work well too, 16 | but I have not tested. 17 | 18 | - png++ relies on GNU make for compiling tests and examples; in 19 | particular it uses "remaking makefiles" feature. 20 | 21 | - Documentation is produced using doxygen (http://www.doxygen.org/). 22 | 23 | 24 | Installation 25 | ============ 26 | 27 | Follow these instructions in order to install png++: 28 | 29 | - Unpack source package: 30 | 31 | $ tar -zxf png++-0.2.x.tar.gz -C ~/src 32 | 33 | - Go to your brand new png++ sources directory: 34 | 35 | $ cd ~/src/png++-0.2.x 36 | 37 | - Issue make to test how it's doing: 38 | 39 | $ make 40 | 41 | This will compile examples in the example/ directory. 42 | 43 | As always, CFLAGS and LDFLAGS could be used to adjust compilation. In 44 | addition, you might want to specify custom libpng-config. Use 45 | LIBPNG_CONFIG variable for that purpose, like this: 46 | 47 | $ make LIBPNG_CONFIG=~/bin/libpng-config 48 | 49 | If everything goes well, try: 50 | 51 | $ make test 52 | 53 | (or "make check" which is the same as above). This will run the test 54 | suite. If tests do not produce error messages then probably all is 55 | OK. 56 | 57 | - Now you can create documentation (optional). Use 58 | 59 | $ make docs 60 | 61 | to run doxygen in the sources directory. 62 | 63 | - Now it is time to become root and install png++ into your system: 64 | 65 | # make install 66 | 67 | It's OK to issue "make install" under ordinary user permissions if you 68 | want to install png++ into your home directory. Run the following 69 | command: 70 | 71 | $ make install PREFIX=$HOME 72 | 73 | This will copy png++ header files to ~/include/png++ and documentation 74 | files to ~/share/doc/png++-0.2.x (if the docs were built). 75 | 76 | Without a PREFIX png++ installs to /usr/local 77 | 78 | 79 | Happy hacking! 80 | -- 81 | Alex Shulgin 82 | -------------------------------------------------------------------------------- /src/pages/png++/config.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2008 Alex Shulgin 3 | * 4 | * This file is part of png++ the C++ wrapper for libpng. PNG++ is free 5 | * software; the exact copying conditions are as follows: 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 23 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 25 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef PNGPP_CONFIG_HPP_INCLUDED 32 | #define PNGPP_CONFIG_HPP_INCLUDED 33 | 34 | // Endianness test 35 | #if defined(__GLIBC__) 36 | 37 | #include 38 | 39 | #elif defined(__WIN32) 40 | 41 | #define __LITTLE_ENDIAN 1234 42 | #define __BIG_ENDIAN 4321 43 | #define __BYTE_ORDER __LITTLE_ENDIAN 44 | 45 | #elif defined(__APPLE__) 46 | 47 | #include 48 | #include 49 | 50 | #elif defined(__FreeBSD__) 51 | 52 | #include 53 | #include 54 | 55 | #else 56 | 57 | #error Byte-order could not be detected. 58 | 59 | #endif 60 | 61 | #endif // PNGPP_CONFIG_HPP_INCLUDED 62 | -------------------------------------------------------------------------------- /src/pages/png++/README: -------------------------------------------------------------------------------- 1 | This is png++ the C++ wrapper for libpng. Version 0.2 2 | 3 | General 4 | ======= 5 | 6 | PNG++ aims to provide simple yet powerful C++ interface to libpng, the 7 | PNG reference implementation library. 8 | 9 | PNG++ is free software distributed under a modified variant of BSD 10 | license. For more details please refer to file COPYING in this 11 | directory. 12 | 13 | Using raw libpng in C++ may impose serious challenge since lots of 14 | precautions must be taken to handle initialization/deinitialization of 15 | control structures as well as handling errors correctly. With png++ 16 | you can read or write PNG images just in a single line of C++ code: 17 | 18 | png::image< png::rgb_pixel > image("input.png"); 19 | image.write("output.png"); 20 | 21 | The code reads an image from the file named "input.png", then writes 22 | the image to a file named "output.png". In this example png++ does 23 | all the transformations needed to create adequate in-memory RGB 24 | representation of the image (well, in most cases it simply instructs 25 | libpng to do so). 26 | 27 | The image in "input.png" can be RGB image, or it might be grayscale or 28 | even indexed image with a palette--png++ will just convert any input 29 | to RGB format. However, for technical reasons such automatic 30 | transformation is supported for RGB and Grayscale color types only. 31 | Optionally there may be an alpha channel in the target color space 32 | (RGBA and Gray+Alpha respectively). 33 | 34 | 35 | Download 36 | ======== 37 | 38 | The project is hosted at Savannah: 39 | 40 | http://savannah.nongnu.org/projects/pngpp/ 41 | 42 | Released source packages can be found here: 43 | 44 | http://download.savannah.nongnu.org/releases/pngpp/ 45 | 46 | Also, you can check out sources directly from SVN repository: 47 | 48 | svn://svn.sv.nongnu.org/pngpp/trunk/ 49 | 50 | or, for people w/o outgoing svn: 51 | 52 | http://svn.sv.nongnu.org/pngpp/trunk/ 53 | 54 | Online documentation can be found here: 55 | 56 | http://www.nongnu.org/pngpp/doc/html/index.html 57 | 58 | 59 | Help 60 | ==== 61 | 62 | There is a mailing list for developers: 63 | 64 | http://lists.nongnu.org/mailman/listinfo/pngpp-devel 65 | 66 | You can also contact me by dropping a mail to . 67 | 68 | 69 | Happy hacking! 70 | -- 71 | Alex Shulgin 72 | -------------------------------------------------------------------------------- /src/pages/PostPage.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "PostPage.hpp" 18 | #include "../api/Api.hpp" 19 | #include "../api/ApiHandler.hpp" 20 | #include "../exceptions/utils.hpp" 21 | 22 | #include "Styler.hpp" 23 | 24 | using namespace std; 25 | using namespace HTML; 26 | 27 | string PostPage::serve( vector args, vector
    &headers ) const{ 28 | require( args.size() == 3, "fail" ); 29 | Api& api = ApiHandler::get_instance()->get_by_shorthand( args[1] ); 30 | UrlHandler url( &api ); 31 | 32 | std::string id_str = args[2]; 33 | bool force_refresh = id_str.size()>1 && id_str[0] == '!'; 34 | if (force_refresh) 35 | id_str = id_str.substr(1); 36 | unsigned id = getInt( id_str, "Post id not an number!" ); 37 | Post post = api.get_post( id, Image::ORIGINAL, force_refresh ); 38 | 39 | Styler s( &api, "Post: " + url.image_tags( post, 128 ) ); 40 | headers.push_back( content_type() ); 41 | 42 | //Quick link to image 43 | //TODO: change behaviour once we have pools 44 | s.head( link(s.doc, REL("next"), HREF( url.image_url( post, Image::ORIGINAL, true ) ) ) ); 45 | 46 | s.head( link(s.doc, REL("shortcut icon"), HREF( "/favicon/" + api.get_shorthand() + "/post" ) ) ); 47 | 48 | auto navi = s.main_navigation( "" ); 49 | s.other_actions( 50 | li(s.doc)( a(s.doc, HREF( url.image_url( post, Image::ORIGINAL, true ) ))( "Save post" ) ) 51 | ); 52 | s.nav( navi ); 53 | 54 | //Post info 55 | auto info = aside( s.doc, CLASS( "post_info" ) ); 56 | info( h3(s.doc)( "Info:" ) ); 57 | s.post_info( info, post, true ); 58 | 59 | s.tag_list( info, api.tag_handler.getAll( post.tags ), "Tags:" ); 60 | 61 | s.body( 62 | div( s.doc, ID("container") )( 63 | s.post( post ) 64 | , info 65 | ) 66 | ); 67 | 68 | return s.doc; 69 | } 70 | -------------------------------------------------------------------------------- /src/parsing/JsonDataNode.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef JSON_DATA_NODE_H 18 | #define JSON_DATA_NODE_H 19 | 20 | #include "DataNodeInterface.hpp" 21 | #include "DataNode.hpp" 22 | #include "NullDataNode.hpp" 23 | #include 24 | 25 | class JsonDataNode : public DataNodeInterface{ 26 | public: 27 | static DataNodeInterface* get_instance(){ 28 | static JsonDataNode* instance = NULL; 29 | return instance ? instance : instance = new JsonDataNode(); 30 | } 31 | 32 | static DataNode from_string( std::string str ){ 33 | json_t* parsed = json_loads( str.c_str(), 0, NULL ); 34 | return DataNode( parsed, parsed ? get_instance() : NullDataNode::get_instance() ); 35 | } 36 | static DataNode from_file( std::string path ){ 37 | json_t* parsed = json_load_file( path.c_str(), 0, NULL ); 38 | return DataNode( parsed, parsed ? get_instance() : NullDataNode::get_instance() ); 39 | } 40 | 41 | virtual bool is_valid( void* p ) const{ return !json_is_null( (json_t*)p ); } 42 | 43 | virtual bool as_boolean( void* p ) const{ 44 | return json_is_boolean( (json_t*)p ); 45 | } 46 | virtual int as_int( void* p ) const{ 47 | return json_integer_value( (json_t*)p ); 48 | } 49 | virtual std::string as_string( void* p ) const{ 50 | const char* str = json_string_value( (json_t*)p ); 51 | return str ? std::string( str ) : ""; 52 | } 53 | 54 | virtual void* get_by_name( void* p, const std::string& child_name ) const{ 55 | return json_object_get( (json_t*)p, child_name.c_str() ); 56 | } 57 | virtual void* get_by_index( void* p, const int index ) const{ 58 | return json_array_get( (json_t*)p, index ); 59 | } 60 | virtual unsigned size( void* p ) const{ return json_array_size( (json_t*)p ); } 61 | }; 62 | 63 | #endif 64 | 65 | -------------------------------------------------------------------------------- /src/parsing/OpenSearchDescription.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "OpenSearchDescription.hpp" 18 | 19 | using namespace std; 20 | using namespace pugi; 21 | 22 | OpenSearchDescription::OpenSearchDescription( const xml_document& doc ) : OpenSearchDescription(){ 23 | load_internal( (xml_node&)doc, xmlns, short_name, description, contact, tags, long_name, developer, attribution, adult_content, language, input_encoding, output_encoding ); 24 | 25 | auto open_search = doc.child( name ); 26 | for( auto it : open_search.children( "Url" ) ){ 27 | Url url; 28 | url.load( it ); 29 | urls.push_back( url ); 30 | } 31 | for( auto it : open_search.children( "Image" ) ){ 32 | Image img; 33 | img.load( it ); 34 | images.push_back( img ); 35 | } 36 | } 37 | 38 | static string to_string( const pugi::xml_document& doc ){ 39 | struct xml_string_writer : pugi::xml_writer{ 40 | std::string result; 41 | virtual void write( const void* data, size_t size ) override{ 42 | result += std::string( static_cast( data ), size ); 43 | } 44 | } writer; 45 | doc.print( writer ); 46 | return writer.result; 47 | } 48 | 49 | string OpenSearchDescription::save(/* const pugi::xml_document& doc */) const{ 50 | xml_document doc; 51 | 52 | auto decl = doc.prepend_child( node_declaration ); 53 | decl.append_attribute( "version" ) = "1.0"; 54 | decl.append_attribute( "encoding" ) = "UTF-8"; 55 | 56 | save_internal( (xml_node&)doc, xmlns, short_name, description, contact, tags, long_name, developer, attribution, adult_content, language, input_encoding, output_encoding ); 57 | 58 | auto open_search = doc.child( name ); 59 | for( auto url : urls ) 60 | url.save( open_search ); 61 | for( auto image : images ) 62 | image.save( open_search ); 63 | 64 | return to_string( doc ); 65 | } 66 | -------------------------------------------------------------------------------- /src/pages/RssPage.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "RssPage.hpp" 18 | 19 | #include 20 | #include 21 | 22 | #include "../api/Api.hpp" 23 | #include "../api/ApiHandler.hpp" 24 | #include "../exceptions/utils.hpp" 25 | #include "../parsing/Rss.hpp" 26 | #include "UrlHandler.hpp" 27 | 28 | using namespace std; 29 | using namespace pugi; 30 | 31 | string RssPage::serve( vector args, vector
    &headers ) const{ 32 | require( args.size() >= 2, "fail" ); 33 | Api& api = ApiHandler::get_instance()->get_by_shorthand( args[1] ); 34 | UrlHandler url( &api ); 35 | 36 | string search = (args.size() == 2) ? "" : args.back(); 37 | int page = 1; 38 | if( args.size() == 4 ) 39 | try{ page = stoi( args[2] ); } 40 | catch(...){ } 41 | 42 | Index index = api.get_index( search, page ); 43 | vector& posts = index.posts; 44 | 45 | Rss rss; 46 | rss.title.value = api.get_name() + " - " + search; 47 | rss.link.value = url.index_url( {{search}} ); 48 | //TODO: link to next page 49 | 50 | Time current; 51 | for( auto post : posts ){ 52 | Rss::Item item{ "item" }; 53 | item.title.value = url.image_tags( post, 128 ); 54 | item.link.value = url.post_url( post.id ); 55 | item.description.value = ""; 56 | item.media_thumbnail.url.value = post.thumbnail.url; 57 | item.media_content.url.value = post.full.url; 58 | item.guid.value = item.link.value; 59 | item.guid_isPermaLink = true; 60 | 61 | if( post.creation_time.isValid() ) 62 | current = post.creation_time; 63 | 64 | item.pubDate.value = current.formatRFC822(); 65 | current.addSeconds( -1 ); //Decrease it with a second 66 | 67 | rss.items.push_back( item ); 68 | } 69 | 70 | headers.push_back( header( "Content-Type", "application/rss+xml" ) ); 71 | return rss.save(); 72 | } 73 | 74 | -------------------------------------------------------------------------------- /src/pages/png++/color.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007,2008 Alex Shulgin 3 | * 4 | * This file is part of png++ the C++ wrapper for libpng. PNG++ is free 5 | * software; the exact copying conditions are as follows: 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 23 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 25 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef PNGPP_COLOR_HPP_INCLUDED 32 | #define PNGPP_COLOR_HPP_INCLUDED 33 | 34 | #include "types.hpp" 35 | 36 | namespace png 37 | { 38 | 39 | /** 40 | * \brief PNG color struct extension. Adds constructors. 41 | */ 42 | struct color 43 | : png_color 44 | { 45 | explicit color(byte r = 0, byte g = 0, byte b = 0) 46 | { 47 | this->red = r; 48 | this->green = g; 49 | this->blue = b; 50 | } 51 | 52 | /** 53 | * \brief Initializes color with a copy of png_color object. 54 | */ 55 | color(png_color const& other) 56 | { 57 | this->red = other.red; 58 | this->green = other.green; 59 | this->blue = other.blue; 60 | } 61 | }; 62 | 63 | } // namespace png 64 | 65 | #endif // PNGPP_COLOR_HPP_INCLUDED 66 | -------------------------------------------------------------------------------- /src/pages/SavePage.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "SavePage.hpp" 18 | #include "ProxyPage.hpp" 19 | #include "UrlHandler.hpp" 20 | #include "../exceptions/utils.hpp" 21 | #include "../exceptions/ResourceMissing.hpp" 22 | 23 | #include "../api/Api.hpp" 24 | #include "../api/ApiHandler.hpp" 25 | 26 | #include "Styler.hpp" 27 | 28 | #include 29 | 30 | using namespace std; 31 | 32 | static string messagePage( const Api& api, string message ){ 33 | BasicStyler s( "Saved" ); 34 | s.body( HTML::p( s.doc )( message ) ); 35 | s.head( link( s.doc, HTML::REL("shortcut icon"), HTML::HREF( "/favicon/" + api.get_shorthand() + "/saved" ) ) ); 36 | return s.doc; 37 | } 38 | 39 | 40 | string SavePage::serve( vector args, vector
    &headers ) const{ 41 | require( args.size() == 3, "fail" ); 42 | 43 | //Parse parameters 44 | auto input = ProxyPage::parseParameters( args ); 45 | Api& api = ApiHandler::get_instance()->get_by_shorthand( input.site ); 46 | auto post = api.get_post( input.id, input.level ); 47 | Image img = post.get_image_size( input.level ); 48 | auto filename = "out/" + args[2]; 49 | 50 | //Sanity checking 51 | if( img.isLocal() ){ 52 | if( !post.saved ){ 53 | debug( "Database inconsistency, image is local, but not saved" ); 54 | post.saved = true; 55 | api.booru.save( post ); 56 | } 57 | 58 | return messagePage( api, "Already saved" ); 59 | } 60 | 61 | //Save file 62 | auto result = ProxyPage().getImage( api, post, img ); 63 | ofstream file( filename, ios_base::out | ios_base::binary ); 64 | result.first->writeAll( file ); 65 | 66 | //Save post in DB 67 | post.saved = true; 68 | post.full.setLocalPath( filename ); //TODO: Bug if input.level differs! 69 | api.booru.save( post ); 70 | 71 | return redirect_page( UrlHandler( &api ).image_url( post, input.level ) ); 72 | // return messagePage( api, "Saved" ); 73 | } 74 | 75 | -------------------------------------------------------------------------------- /src/parsing/Rss.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "Rss.hpp" 18 | 19 | using namespace std; 20 | using namespace pugi; 21 | 22 | Rss::Rss( const xml_document& doc ) : Rss(){ 23 | auto rss = doc.child("rss"); 24 | auto channel = rss.child("channel"); 25 | 26 | load_internal( rss, title, link, description, language, copyright, managingEditor, webMaster, pubDate, lastBuildDate, category, generator, docs, ttl ); 27 | 28 | for( auto it : channel.children( "item" ) ){ 29 | Item item{ "item" }; 30 | item.load( it ); 31 | items.push_back( item ); 32 | } 33 | } 34 | 35 | static string to_string( const pugi::xml_document& doc ){ 36 | struct xml_string_writer : pugi::xml_writer{ 37 | std::string result; 38 | virtual void write( const void* data, size_t size ) override{ 39 | result += std::string( static_cast( data ), size ); 40 | } 41 | } writer; 42 | doc.print( writer ); 43 | return writer.result; 44 | } 45 | 46 | static void add_optional( xml_node& node, const char* name, string value ){ 47 | if( !value.empty() ) 48 | node.append_child( name ).append_child(pugi::node_pcdata).set_value( value.c_str() ); 49 | } 50 | 51 | string Rss::save(/* const pugi::xml_document& doc */) const{ 52 | xml_document doc; 53 | 54 | auto decl = doc.prepend_child( node_declaration ); 55 | decl.append_attribute( "version" ) = "1.0"; 56 | decl.append_attribute( "encoding" ) = "UTF-8"; 57 | 58 | auto root = doc.append_child( "rss" ); 59 | root.append_attribute( "version" ) = "2.0"; 60 | root.append_attribute( "xmlns:media" ) = "http://search.yahoo.com/mrss/"; 61 | 62 | save_internal( root, title, link, description, language, copyright, managingEditor, webMaster, pubDate, lastBuildDate, category, generator, docs, ttl ); 63 | 64 | auto channel = root.child("channel"); 65 | for( auto item : items ) 66 | item.save( channel ); 67 | 68 | return to_string( doc ); 69 | } 70 | -------------------------------------------------------------------------------- /src/db/AddLocal.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of rss2rss. 2 | 3 | rss2rss is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | rss2rss is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with rss2rss. If not, see . 15 | */ 16 | 17 | #include "AddLocal.hpp" 18 | 19 | #include "../api/Api.hpp" 20 | #include "../api/ApiHandler.hpp" 21 | #include "../objects/Post.hpp" 22 | #include "../parsing/StringViewUtils.hpp" 23 | 24 | #include 25 | 26 | #include 27 | #include 28 | 29 | using namespace std; 30 | using namespace Poco; 31 | 32 | void addFolder( string dir_path ){ 33 | int amount = 0; 34 | DirectoryIterator it( { dir_path } ), end; 35 | for( ; it != end; ++it, amount++ ) 36 | try{ 37 | auto parts = splitAllOn( it.path().getBaseName(), ' ' ); 38 | removeEmpty( parts ); 39 | if( it->isFile() && parts.size() >= 2 ){ 40 | auto& api = ApiHandler::get_instance()->get_by_shorthand( std::string(parts[0]) ); //TODO: Avoid string conversion 41 | 42 | Post p( stoi( std::string(parts[1]) ) ); 43 | for( unsigned i=2, type=0; icreated().epochTime() ); 63 | auto current = it.path(); 64 | p.full.url = "file:///" + current.makeAbsolute().toString(); 65 | 66 | api.post_handler.add( p ); 67 | } 68 | else if( it->isDirectory() ){ 69 | auto current = it.path(); 70 | addFolder( current.makeAbsolute().toString() ); 71 | } 72 | } catch( ... ) { } 73 | cout << "Total local files: " << amount << '\n'; 74 | } 75 | 76 | -------------------------------------------------------------------------------- /src/db/Statement.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of rss2rss. 2 | 3 | rss2rss is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | rss2rss is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with rss2rss. If not, see . 15 | */ 16 | 17 | #ifndef STATEMENT_HPP 18 | #define STATEMENT_HPP 19 | 20 | #include "Database.hpp" 21 | 22 | #include 23 | #include 24 | 25 | struct sqlite3; 26 | struct sqlite3_stmt; 27 | 28 | class Statement{ 29 | private: 30 | sqlite3_stmt *stmt{ nullptr }; 31 | Database& db; 32 | const char* query; 33 | 34 | public: 35 | Statement( Database& db, const char* query ); 36 | Statement( const Statement& ) = delete; 37 | Statement( Statement&& other ) 38 | : stmt( other.stmt ), db( other.db ), query( other.query ) { 39 | other.stmt = nullptr; 40 | other.query = nullptr; 41 | } 42 | ~Statement(); 43 | 44 | [[ noreturn ]] void throwError( std::string error ); 45 | 46 | bool next(); 47 | bool reset(); 48 | 49 | int columnType( unsigned column ); 50 | 51 | std::string text( unsigned column ); 52 | bool boolean( unsigned column ); 53 | int integer( unsigned column ); 54 | int64_t integer64( unsigned column ); 55 | double floating( unsigned column ); 56 | 57 | void bind( std::string value, unsigned column ); 58 | void bind( bool value, unsigned column ); 59 | void bind( int value, unsigned column ); 60 | void bind( int64_t value, unsigned column ); 61 | void bind( double value, unsigned column ); 62 | 63 | }; 64 | 65 | class Transaction{ 66 | private: 67 | Database* db; 68 | bool commit{ true }; 69 | 70 | public: 71 | Transaction( Database& db ) : db(&db) { Statement( db, "BEGIN TRANSACTION" ).next(); } 72 | Transaction( const Transaction& ) = delete; 73 | Transaction( Transaction&& other ) : db( other.db ){ other.commit = false; } 74 | ~Transaction(){ close(); } 75 | 76 | Transaction& operator=( const Transaction& other ) = delete; 77 | Transaction& operator=( Transaction&& other ){ 78 | db = other.db; 79 | commit = other.commit; 80 | other.commit = false; 81 | return *this; 82 | } 83 | 84 | void close(); 85 | }; 86 | 87 | #endif 88 | 89 | -------------------------------------------------------------------------------- /src/pages/png++/end_info.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007,2008 Alex Shulgin 3 | * 4 | * This file is part of png++ the C++ wrapper for libpng. PNG++ is free 5 | * software; the exact copying conditions are as follows: 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 23 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 25 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef PNGPP_END_INFO_HPP_INCLUDED 32 | #define PNGPP_END_INFO_HPP_INCLUDED 33 | 34 | #include "info_base.hpp" 35 | 36 | namespace png 37 | { 38 | 39 | /** 40 | * \brief Internal class to hold PNG ending %info. 41 | * 42 | * \see info, info_base 43 | */ 44 | class end_info 45 | : public info_base 46 | { 47 | public: 48 | end_info(io_base& io, png_struct* png) 49 | : info_base(io, png) 50 | { 51 | } 52 | 53 | void destroy() 54 | { 55 | assert(m_info); 56 | png_destroy_info_struct(m_png, & m_info); 57 | } 58 | 59 | void read() 60 | { 61 | png_read_end(m_png, m_info); 62 | } 63 | 64 | void write() const 65 | { 66 | png_write_end(m_png, m_info); 67 | } 68 | 69 | // TODO: add methods to read/write text comments etc. 70 | }; 71 | 72 | } // namespace png 73 | 74 | #endif // PNGPP_END_INFO_HPP_INCLUDED 75 | -------------------------------------------------------------------------------- /src/pages/Styler.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef STYLER_H 18 | #define STYLER_H 19 | 20 | #include "../parsing/html.hpp" 21 | #include "UrlHandler.hpp" 22 | 23 | #include 24 | 25 | class Post; 26 | class Time; 27 | class Tag; 28 | class Comment; 29 | class Pool; 30 | class Note; 31 | class Image; 32 | class Api; 33 | 34 | std::string redirect_page( std::string url ); 35 | 36 | class BasicStyler{ 37 | public: 38 | HTML::Document doc; 39 | HTML::Node head{ HTML::head(doc) }; 40 | HTML::Node body{ HTML::body(doc) }; 41 | HTML::Node nav{ HTML::nav(doc) }; 42 | HTML::Node other_actions{ HTML::ul(doc) }; 43 | HTML::Node container{ HTML::div( doc, HTML::ID("container") ) }; 44 | 45 | BasicStyler( std::string title ); 46 | 47 | std::string format_filesize( unsigned filesize ) const; 48 | std::string format_date( Time timestamp ) const; 49 | HTML::Node time( unsigned unix_time ); 50 | }; 51 | 52 | class Styler : public BasicStyler{ 53 | public: 54 | Api* api; 55 | UrlHandler url; 56 | 57 | public: 58 | Styler( Api* api, std::string title ); 59 | 60 | HTML::Node tag_search(); 61 | HTML::Node main_navigation( std::string search ); 62 | 63 | HTML::Node tag( const Tag& tag ); 64 | void tag_list( HTML::Node& parent, const std::vector& tags, std::string title="" ); 65 | 66 | HTML::Node note( const Note& note ); 67 | HTML::Node comment( const Comment& comment ); 68 | 69 | HTML::Node post_preview( const Post& post ); 70 | 71 | 72 | HTML::Node post_thumb( const Post& post ); 73 | HTML::Node post_thumb_info( const Post& post, bool extended=false ); 74 | HTML::Node post_details( const Post& post ); 75 | 76 | HTML::Node post( Post post ); 77 | HTML::Node post_info( HTML::Node& parent, const Post& post, bool extended=false ); 78 | HTML::Node post_list( std::vector list ); 79 | HTML::Node post_list_section( std::vector list ); 80 | 81 | HTML::Node index_navigation( std::string search, int page, int limit, int amount ); 82 | }; 83 | 84 | #endif 85 | 86 | -------------------------------------------------------------------------------- /src/api/Api.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef API_HPP 18 | #define API_HPP 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include "../objects/ResourceHandler.hpp" 27 | #include "../objects/Post.hpp" 28 | #include "../objects/Note.hpp" 29 | #include "../objects/Tag.hpp" 30 | #include "../objects/Index.hpp" 31 | 32 | namespace Poco{ namespace Net { 33 | class HTTPClientSession; 34 | } } 35 | 36 | class Api{ 37 | protected: 38 | std::string site_name; 39 | 40 | public: 41 | Booru booru{ site_name }; 42 | struct ThemeColor{ 43 | int red, green, blue; 44 | }; 45 | ResourceHandler tag_handler{ booru }; 46 | ResourceHandler post_handler{ booru }; 47 | ResourceHandler note_handler{ booru }; 48 | void flush(); 49 | public: 50 | using Headers = std::vector>; 51 | using UrlResponse = std::pair,std::istream&>; 52 | 53 | UrlResponse getFromUrl( std::string url, Headers headers = Headers() ) const; 54 | std::string get_from_url( std::string url, Headers headers = Headers() ) const; //temporary 55 | 56 | public: 57 | Api( std::string site_name ) : site_name(site_name) { } 58 | virtual std::string get_name() const = 0; 59 | virtual std::string get_shorthand() const{ return site_name; } 60 | virtual std::string get_url() const = 0; 61 | 62 | virtual Post fetch_post( unsigned id, Image::Size level ) = 0; 63 | virtual Post get_post( unsigned id, Image::Size level=Image::ORIGINAL, bool force_refresh=false ); 64 | virtual Index get_index( std::string search, int page, int limit=-1 ) = 0; 65 | 66 | virtual ThemeColor main_color(){ return {255,255,255}; } 67 | virtual ThemeColor secondary_color(){ return {0,0,0}; } 68 | 69 | virtual std::string original_post_url( unsigned id ) = 0; 70 | virtual std::string original_index_url( std::string search ) = 0; 71 | 72 | virtual ~Api(){ } 73 | }; 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /src/pages/png++/info_base.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007,2008 Alex Shulgin 3 | * 4 | * This file is part of png++ the C++ wrapper for libpng. PNG++ is free 5 | * software; the exact copying conditions are as follows: 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 23 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 25 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef PNGPP_INFO_BASE_HPP_INCLUDED 32 | #define PNGPP_INFO_BASE_HPP_INCLUDED 33 | 34 | #include 35 | #include "error.hpp" 36 | #include "types.hpp" 37 | 38 | namespace png 39 | { 40 | 41 | class io_base; 42 | 43 | /** 44 | * \brief Internal class to hold PNG info or end_info. 45 | */ 46 | class info_base 47 | { 48 | info_base(info_base const&); 49 | info_base& operator=(info_base const&); 50 | 51 | public: 52 | info_base(io_base& io, png_struct* png) 53 | : m_io(io), 54 | m_png(png), 55 | m_info(png_create_info_struct(m_png)) 56 | { 57 | } 58 | 59 | png_info* get_png_info() const 60 | { 61 | return m_info; 62 | } 63 | 64 | png_info** get_png_info_ptr() 65 | { 66 | return & m_info; 67 | } 68 | 69 | protected: 70 | io_base& m_io; 71 | png_struct* m_png; 72 | png_info* m_info; 73 | }; 74 | 75 | } // namespace png 76 | 77 | #endif // PNGPP_INFO_BASE_HPP_INCLUDED 78 | -------------------------------------------------------------------------------- /src/parsing/OpenSearchDescription.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef OPEN_SEARCH_DESCRIPTION_HPP 18 | #define OPEN_SEARCH_DESCRIPTION_HPP 19 | 20 | #include "XmlBase.hpp" 21 | 22 | class OpenSearchDescription : Structure{ 23 | private: 24 | Attribute<> xmlns{ "xmlns", "http://a9.com/-/spec/opensearch/1.1/" }; 25 | 26 | public: 27 | struct Url : Structure{ 28 | Attribute<> temp{ "template" }; 29 | Attribute<> type{ "type" }; 30 | Attribute<> rel{ "rel" }; 31 | Attribute indexOffset{ "indexOffset", -1 }; 32 | Attribute pageOffset{ "pageOffset", -1 }; 33 | 34 | Url() : Structure( "Url" ) { } 35 | void save( pugi::xml_node& node ) const 36 | { save_internal( node, temp, type, rel, indexOffset, pageOffset ); } 37 | void load( pugi::xml_node& node ) 38 | { load_internal( node, temp, type, rel, indexOffset, pageOffset ); } 39 | }; 40 | 41 | struct Image : Structure{ 42 | Attribute height{ "height", -1 }; 43 | Attribute width{ "width", -1 }; 44 | Attribute<> type{ "type" }; 45 | 46 | Image() : Structure( "Image" ) { } 47 | void save( pugi::xml_node& node ) const 48 | { save_internal( node, width, height, type ); } 49 | void load( pugi::xml_node& node ) 50 | { load_internal( node, width, height, type ); } 51 | }; 52 | public: //Root attributes 53 | //Required 54 | Value<> short_name{ "ShortName" }; 55 | Value<> description{ "Description" }; 56 | 57 | std::vector urls; 58 | 59 | //Optional 60 | Value<> contact{ "Contact" }; 61 | Value<> tags{ "Tags" }; 62 | Value<> long_name{ "LongName" }; 63 | std::vector images; 64 | Value<> developer{ "Developer" }; 65 | Value<> attribution{ "Attribution" }; 66 | //SyndicationRight 67 | Value adult_content{ "AdultContent", false }; 68 | Value<> language{ "Language" }; 69 | Value<> input_encoding{ "InputEncoding" }; 70 | Value<> output_encoding{ "OutputEncoding" }; 71 | 72 | public: //Parsing 73 | OpenSearchDescription() : Structure("OpenSearchDescription"){ } 74 | OpenSearchDescription( const pugi::xml_document& doc ); 75 | 76 | std::string save(/* const pugi::xml_document& doc */) const; 77 | }; 78 | 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /src/parsing/DataNode.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef DATA_NODE_H 18 | #define DATA_NODE_H 19 | 20 | #include "DataNodeInterface.hpp" 21 | #include "NullDataNode.hpp" 22 | #include 23 | 24 | class DataNode{ 25 | private: 26 | void* node; 27 | DataNodeInterface* interface; 28 | 29 | public: 30 | class Iterator{ 31 | private: 32 | const DataNode& node; 33 | unsigned pos; 34 | 35 | public: 36 | Iterator( const DataNode& node, unsigned pos ) : node( node ){ 37 | this->pos = pos; 38 | } 39 | 40 | bool operator!=( const Iterator& other ) const{ 41 | return pos != other.pos; 42 | } 43 | const Iterator& operator++(){ 44 | pos++; 45 | return *this; 46 | } 47 | DataNode operator*() const{ return node[pos]; } 48 | }; 49 | 50 | public: 51 | DataNode(){ 52 | interface = NullDataNode::get_instance(); 53 | } 54 | 55 | DataNode( void* n, DataNodeInterface* i ){ 56 | node = n; 57 | interface = i; 58 | } 59 | 60 | bool is_valid() const{ return interface->is_valid( node ); } 61 | 62 | bool as_boolean() const{ return interface->as_boolean( node ); } 63 | int as_int() const{ return interface->as_int( node ); } 64 | std::string as_string() const{ return interface->as_string( node ); } 65 | 66 | DataNode operator[] ( const std::string& child_name ) const{ 67 | return DataNode( interface->get_by_name( node, child_name ), interface ); 68 | } 69 | DataNode operator[] ( const char* child_name ) const{ 70 | return DataNode( interface->get_by_name( node, std::string(child_name) ), interface ); 71 | } 72 | DataNode operator[] ( const int index ) const{ 73 | return DataNode( interface->get_by_index( node, index ), interface ); 74 | } 75 | unsigned size() const{ return interface->size( node ); } 76 | 77 | Iterator begin() const{ return Iterator( *this, 0 ); } 78 | Iterator end() const{ 79 | //TODO: how should size==0 be handled? 80 | unsigned amount = size(); 81 | return Iterator( *this, amount ? amount-1 : 0 ); 82 | } 83 | 84 | operator bool() const{ return is_valid(); } 85 | operator int() const{ return as_int(); } 86 | operator std::string() const{ return as_string(); } 87 | }; 88 | 89 | #endif 90 | 91 | -------------------------------------------------------------------------------- /src/parsing/pugiconfig.hpp: -------------------------------------------------------------------------------- 1 | /** 2 | * pugixml parser - version 1.2 3 | * -------------------------------------------------------- 4 | * Copyright (C) 2006-2012, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com) 5 | * Report bugs and download new versions at http://pugixml.org/ 6 | * 7 | * This library is distributed under the MIT License. See notice at the end 8 | * of this file. 9 | * 10 | * This work is based on the pugxml parser, which is: 11 | * Copyright (C) 2003, by Kristen Wegner (kristen@tima.net) 12 | */ 13 | 14 | #ifndef HEADER_PUGICONFIG_HPP 15 | #define HEADER_PUGICONFIG_HPP 16 | 17 | // Uncomment this to enable wchar_t mode 18 | // #define PUGIXML_WCHAR_MODE 19 | 20 | // Uncomment this to disable XPath 21 | // #define PUGIXML_NO_XPATH 22 | 23 | // Uncomment this to disable STL 24 | // #define PUGIXML_NO_STL 25 | 26 | // Uncomment this to disable exceptions 27 | // #define PUGIXML_NO_EXCEPTIONS 28 | 29 | // Set this to control attributes for public classes/functions, i.e.: 30 | // #define PUGIXML_API __declspec(dllexport) // to export all public symbols from DLL 31 | // #define PUGIXML_CLASS __declspec(dllimport) // to import all classes from DLL 32 | // #define PUGIXML_FUNCTION __fastcall // to set calling conventions to all public functions to fastcall 33 | // In absence of PUGIXML_CLASS/PUGIXML_FUNCTION definitions PUGIXML_API is used instead 34 | 35 | // Uncomment this to switch to header-only version 36 | // #define PUGIXML_HEADER_ONLY 37 | // #include "pugixml.cpp" 38 | 39 | // Tune these constants to adjust memory-related behavior 40 | // #define PUGIXML_MEMORY_PAGE_SIZE 32768 41 | // #define PUGIXML_MEMORY_OUTPUT_STACK 10240 42 | // #define PUGIXML_MEMORY_XPATH_PAGE_SIZE 4096 43 | 44 | #endif 45 | 46 | /** 47 | * Copyright (c) 2006-2012 Arseny Kapoulkine 48 | * 49 | * Permission is hereby granted, free of charge, to any person 50 | * obtaining a copy of this software and associated documentation 51 | * files (the "Software"), to deal in the Software without 52 | * restriction, including without limitation the rights to use, 53 | * copy, modify, merge, publish, distribute, sublicense, and/or sell 54 | * copies of the Software, and to permit persons to whom the 55 | * Software is furnished to do so, subject to the following 56 | * conditions: 57 | * 58 | * The above copyright notice and this permission notice shall be 59 | * included in all copies or substantial portions of the Software. 60 | * 61 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 62 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 63 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 64 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 65 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 66 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 67 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 68 | * OTHER DEALINGS IN THE SOFTWARE. 69 | */ 70 | -------------------------------------------------------------------------------- /src/pages/FaviconPage.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "FaviconPage.hpp" 18 | #include "../api/Api.hpp" 19 | #include "../api/ApiHandler.hpp" 20 | #include "../exceptions/utils.hpp" 21 | 22 | #include "png++/png.hpp" 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | using namespace std; 29 | using namespace png; 30 | 31 | 32 | rgb_pixel colorize( Api::ThemeColor c1, Api::ThemeColor c2, gray_pixel from ){ 33 | return rgb_pixel( 34 | (c2.red * from + c1.red * (255-from)) / 255 35 | , (c2.green * from + c1.green * (255-from)) / 255 36 | , (c2.blue * from + c1.blue * (255-from)) / 255 37 | ); 38 | } 39 | 40 | static const unordered_map images{ 41 | {"index", "i"} 42 | , {"post", "p"} 43 | , {"saved", "s"} 44 | }; 45 | string image_path( string wanted ){ 46 | auto pos = images.find( wanted ); 47 | wanted = pos != images.end() ? pos->second : "missing"; 48 | return "data/favicon_" + wanted + ".png"; 49 | } 50 | 51 | string to_string( image img ){ 52 | ostringstream stream; 53 | img.write_stream( stream ); 54 | return stream.str(); 55 | } 56 | 57 | string FaviconPage::serve( vector args, vector
    &headers ) const{ 58 | require( args.size() == 3, "Invalid argument size" ); 59 | Api& api = ApiHandler::get_instance()->get_by_shorthand( args[1] ); 60 | 61 | headers.push_back( header( "Content-Type", "image/png" ) ); 62 | 63 | image img_fail( image_path( "" ) ); 64 | 65 | 66 | try{ 67 | image img_template( image_path( args[2] ) ); 68 | auto main = api.main_color(), secondary = api.secondary_color(); 69 | image img_out( 16, 16 ); 70 | if( img_template.get_width() != img_out.get_width() 71 | && img_template.get_height() != img_out.get_height() ) 72 | throw logic_error( "Favicon template has wrong dimensions" ); 73 | 74 | for( size_t iy=0; iy class allowed_bit_depth; 42 | 43 | template<> class allowed_bit_depth< 1 > {}; 44 | template<> class allowed_bit_depth< 2 > {}; 45 | template<> class allowed_bit_depth< 4 > {}; 46 | } // namespace detail 47 | 48 | /** 49 | * \brief The packed pixel class template. 50 | * 51 | * \see packed_gray_pixel, packed_index_pixel 52 | */ 53 | template< size_t bits > 54 | class packed_pixel 55 | : detail::allowed_bit_depth< bits > 56 | { 57 | public: 58 | packed_pixel(byte value = 0) 59 | : m_value(value & get_bit_mask()) 60 | { 61 | } 62 | 63 | operator byte() const 64 | { 65 | return m_value; 66 | } 67 | 68 | static size_t const get_bit_depth() 69 | { 70 | return bits; 71 | } 72 | 73 | static byte const get_bit_mask() 74 | { 75 | return (1 << bits) - 1; 76 | } 77 | 78 | private: 79 | byte m_value; 80 | }; 81 | 82 | } // namespace png 83 | 84 | #endif // PNGPP_PACKED_PIXEL_HPP_INCLUDED 85 | -------------------------------------------------------------------------------- /src/pages/APage.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "APage.hpp" 18 | 19 | #include "../api/ApiHandler.hpp" 20 | #include "../db/Booru.hpp" 21 | 22 | #include 23 | 24 | #include 25 | 26 | using namespace Poco::Net; 27 | using namespace std; 28 | 29 | static void exceptionErrorPage( HTTPServerResponse& response, exception& e ){ 30 | cout << "Exception occurred: " << e.what() << '\n'; 31 | string contents = "Exception happened during processing the page: "; 32 | contents += e.what(); 33 | response.setStatus( HTTPResponse::HTTP_INTERNAL_SERVER_ERROR ); 34 | response.sendBuffer( contents.c_str(), contents.size() ); 35 | } 36 | 37 | template 38 | void handleRequestExceptions( HTTPServerResponse& response, Func f ){ 39 | try{ f(); } 40 | //TODO: Handle more specific errors 41 | catch( exception& e ){ 42 | resetDatabaseConnections(); 43 | exceptionErrorPage( response, e ); 44 | } 45 | } 46 | 47 | void StringPage::handleRequest( Arguments args, HTTPServerResponse& response ){ 48 | handleRequestExceptions( response, [&](){ 49 | //Create content 50 | vector headers; 51 | string contents = serve( args, headers ); 52 | 53 | //Add headers 54 | response.setStatus( HTTPResponse::HTTP_OK ); 55 | for( APage::header h : headers ) 56 | response.add( h.first, h.second ); 57 | 58 | //Send content 59 | response.sendBuffer( contents.c_str(), contents.size() ); 60 | } ); 61 | 62 | try{ 63 | ApiHandler::get_instance()->flush(); 64 | } 65 | catch( exception& e ){ 66 | resetDatabaseConnections(); 67 | cout << "Flush failed\n"; 68 | } 69 | } 70 | 71 | void StreamPage::Reader::writeAll( std::ostream& out ){ 72 | char buffer[4096]; 73 | int available; 74 | do{ 75 | available = readBuf( buffer, sizeof(buffer) ); 76 | out.write( buffer, available ); 77 | }while( available == sizeof(buffer) ); 78 | } 79 | 80 | void StreamPage::handleRequest( Arguments args, HTTPServerResponse& response ){ 81 | handleRequestExceptions( response, [&](){ 82 | vector headers; 83 | auto reader = serve( args, headers ); 84 | 85 | //Add headers 86 | response.setStatus( HTTPResponse::HTTP_OK ); 87 | for( APage::header h : headers ) 88 | response.add( h.first, h.second ); 89 | 90 | //Write everything from the Reader 91 | reader->writeAll( response.send() ); 92 | } ); 93 | } -------------------------------------------------------------------------------- /styles/_post.scss: -------------------------------------------------------------------------------- 1 | /********** POST START **********/ 2 | .post_parent img, .post_children img{ 3 | max-width:150px; 4 | max-height:150px; 5 | } 6 | .post_parent img:hover, .post_children img:hover{ 7 | /* max-width:none; 8 | max-height:none; */ 9 | -o-object-fit:none; 10 | -o-object-position:left center; 11 | position:relative; 12 | z-index:100; 13 | } 14 | 15 | .post .container{ 16 | display:inline-block; 17 | position:relative; 18 | max-width:100%; 19 | } 20 | .post .container video{ 21 | max-width:100%; 22 | } 23 | .post_info em{ 24 | font-weight:bold; 25 | margin-right: 4px; 26 | } 27 | .post_info p:first-line{ 28 | text-indent:0; 29 | } 30 | .post_info p{ 31 | padding-left:10px; 32 | text-indent:-10px; 33 | } 34 | .post_info p+p{ 35 | margin-top:1px; 36 | } 37 | 38 | /* Make the preview resize with the browser window */ 39 | /* Notice that this requires each div to have 'height:100%'. */ 40 | /* #container have been set to 95% to make the image approax */ 41 | /* fit under the header and avoid extra padding in bottom. */ 42 | /* 43 | html, body, #container > .post, #container > .post > .container, #container > .post > .container > a{height:100%;} 44 | .post .container img{max-height:100%} 45 | #container{height:95%;} 46 | */ 47 | body{margin: 0 0 0 5px;} 48 | .post .container img{ 49 | max-width:100%; 50 | } 51 | 52 | /* Make it possible to tell the image is transparent with a checker-box pattern 53 | * 54 | * NOTE: To make it transition on hover, it had to be done on the parent 55 | * instead of the img, which might cause issues. A fairly restrictive selector 56 | * is used as an attempt to counter that. */ 57 | .post .container a:first-child:before{ 58 | content:""; 59 | position:absolute; 60 | top:0; 61 | left:0; 62 | width:100%; 63 | height:100%; 64 | z-index:-1; 65 | 66 | /* The actual pattern pattern */ 67 | background-color:#555; 68 | background-size:24px 24px; 69 | background-position:0 0, 12px 12px; 70 | background-image: 71 | linear-gradient(45deg, #444 25%, transparent 25%, transparent 75%, #444 75%, #444), 72 | linear-gradient(45deg, #444 25%, transparent 25%, transparent 75%, #444 75%, #444); 73 | 74 | /* Create a smooth transition on hover */ 75 | transition: opacity 0.4s linear; 76 | } 77 | .post .container a:first-child:hover:before{ opacity:0; } 78 | .post .container a:first-child{ display:block; font-size:0; } /* Fix being too large */ 79 | 80 | .post .container object{ 81 | display:block; 82 | } 83 | .post .container div{ 84 | display:block; 85 | position:absolute; 86 | background-color:#ffffee; 87 | background-color:rgba(255,255,238,0.5); 88 | border:1px solid black; 89 | } 90 | .post .container div div{ display:none; } 91 | .post .container div:hover div{ 92 | display:inline; 93 | z-index:1; 94 | top:100%; 95 | left:0; 96 | color:black; 97 | background-color:#ffffee; 98 | width:auto; 99 | max-width:200px; 100 | } 101 | /*** COMMENTS START ***/ 102 | .comments article{ 103 | margin-bottom: 10px; 104 | } 105 | .comments time{ 106 | color:gray; 107 | } 108 | /*** COMMENTS END ***/ 109 | /********** POST END **********/ 110 | -------------------------------------------------------------------------------- /src/pages/png++/ga_pixel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007,2008 Alex Shulgin 3 | * 4 | * This file is part of png++ the C++ wrapper for libpng. PNG++ is free 5 | * software; the exact copying conditions are as follows: 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 23 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 25 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef PNGPP_GA_PIXEL_HPP_INCLUDED 32 | #define PNGPP_GA_PIXEL_HPP_INCLUDED 33 | 34 | #include 35 | 36 | #include "types.hpp" 37 | #include "pixel_traits.hpp" 38 | 39 | namespace png 40 | { 41 | 42 | /** 43 | * \brief Basic Gray+Alpha pixel type. 44 | */ 45 | template< typename T > 46 | struct basic_ga_pixel 47 | { 48 | typedef pixel_traits< basic_ga_pixel< T > > traits; 49 | 50 | /** 51 | * \brief Constructs basic_ga_pixel object from \a value and 52 | * \a alpha components passed as parameters. Alpha defaults 53 | * to full opacity. 54 | */ 55 | basic_ga_pixel(T value = 0, T alpha = traits::get_alpha_filler()) 56 | : value(value), alpha(alpha) 57 | { 58 | } 59 | 60 | T value; 61 | T alpha; 62 | }; 63 | 64 | /** 65 | * \brief The 8-bit Gray+Alpha pixel type. 66 | */ 67 | typedef basic_ga_pixel< byte > ga_pixel; 68 | 69 | /** 70 | * \brief The 16-bit Gray+Alpha pixel type. 71 | */ 72 | typedef basic_ga_pixel< uint_16 > ga_pixel_16; 73 | 74 | /** 75 | * \brief Pixel traits specialization for basic_ga_pixel. 76 | */ 77 | template< typename T > 78 | struct pixel_traits< basic_ga_pixel< T > > 79 | : basic_pixel_traits< basic_ga_pixel< T >, T, color_type_ga >, 80 | basic_alpha_pixel_traits< T > 81 | { 82 | }; 83 | 84 | } // namespace png 85 | 86 | #endif // PNGPP_GA_PIXEL_HPP_INCLUDED 87 | -------------------------------------------------------------------------------- /src/pages/png++/error.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007,2008 Alex Shulgin 3 | * 4 | * This file is part of png++ the C++ wrapper for libpng. PNG++ is free 5 | * software; the exact copying conditions are as follows: 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 23 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 25 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef PNGPP_ERROR_HPP_INCLUDED 32 | #define PNGPP_ERROR_HPP_INCLUDED 33 | 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | namespace png 40 | { 41 | 42 | /** 43 | * \brief Exception class to represent runtime errors related to 44 | * png++ operation. 45 | */ 46 | class error 47 | : public std::runtime_error 48 | { 49 | public: 50 | /** 51 | * \param message error description 52 | */ 53 | explicit error(std::string const& message) 54 | : std::runtime_error(message) 55 | { 56 | } 57 | }; 58 | 59 | /** 60 | * \brief Exception class to represent standard library errors 61 | * (generally IO). 62 | * 63 | * \see reader, writer 64 | */ 65 | class std_error 66 | : public std::runtime_error 67 | { 68 | public: 69 | /** 70 | * Constructs an std_error object. The \a message string is 71 | * appended with ": " and the error description as 72 | * returned by \c strerror(\a error). 73 | * 74 | * \param message error description 75 | * \param error error number 76 | */ 77 | explicit std_error(std::string const& message, int error = errno) 78 | : std::runtime_error((message + ": ") + std::strerror(error)) 79 | { 80 | } 81 | }; 82 | 83 | } // namespace png 84 | 85 | #endif // PNGPP_ERROR_HPP_INCLUDED 86 | -------------------------------------------------------------------------------- /src/pages/png++/rgb_pixel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007,2008 Alex Shulgin 3 | * 4 | * This file is part of png++ the C++ wrapper for libpng. PNG++ is free 5 | * software; the exact copying conditions are as follows: 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 23 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 25 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef PNGPP_RGB_PIXEL_HPP_INCLUDED 32 | #define PNGPP_RGB_PIXEL_HPP_INCLUDED 33 | 34 | #include "types.hpp" 35 | #include "pixel_traits.hpp" 36 | 37 | namespace png 38 | { 39 | 40 | /** 41 | * \brief RGB pixel type. 42 | */ 43 | template< typename T > 44 | struct basic_rgb_pixel 45 | { 46 | /** 47 | * \brief Default constructor. Initializes all components 48 | * with zeros. 49 | */ 50 | basic_rgb_pixel() 51 | : red(0), green(0), blue(0) 52 | { 53 | } 54 | 55 | /** 56 | * \brief Constructs rgb_pixel object from \a red, \a green 57 | * and \a blue components passed as parameters. 58 | */ 59 | basic_rgb_pixel(T red, T green, T blue) 60 | : red(red), green(green), blue(blue) 61 | { 62 | } 63 | 64 | T red; 65 | T green; 66 | T blue; 67 | }; 68 | 69 | /** 70 | * The 8-bit RGB pixel type. 71 | */ 72 | typedef basic_rgb_pixel< byte > rgb_pixel; 73 | 74 | /** 75 | * The 16-bit RGB pixel type. 76 | */ 77 | typedef basic_rgb_pixel< uint_16 > rgb_pixel_16; 78 | 79 | /** 80 | * \brief Pixel traits specialization for basic_rgb_pixel. 81 | */ 82 | template< typename T > 83 | struct pixel_traits< basic_rgb_pixel< T > > 84 | : basic_pixel_traits< basic_rgb_pixel< T >, T, color_type_rgb > 85 | { 86 | }; 87 | 88 | } // namespace png 89 | 90 | #endif // PNGPP_RGB_PIXEL_HPP_INCLUDED 91 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.0) 2 | project(BooruSurfer2) 3 | 4 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) 5 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) 6 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}) 7 | 8 | 9 | # Turn on warnings 10 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") 11 | 12 | 13 | set(SOURCES 14 | src/api/Api.cpp 15 | src/api/ApiHandler.cpp 16 | src/api/DanApi.cpp 17 | src/api/KonachanApi.cpp 18 | src/api/LocalApi.cpp 19 | src/api/SanApi.cpp 20 | src/api/ShimmieApi.cpp 21 | 22 | src/db/AddLocal.cpp 23 | src/db/Booru.cpp 24 | src/db/Database.cpp 25 | src/db/LocalDb.cpp 26 | src/db/Statement.cpp 27 | 28 | src/objects/Comment.cpp 29 | src/objects/Image.cpp 30 | src/objects/Index.cpp 31 | src/objects/Note.cpp 32 | src/objects/Pool.cpp 33 | src/objects/Post.cpp 34 | src/objects/Tag.cpp 35 | 36 | src/pages/APage.cpp 37 | src/pages/FaviconPage.cpp 38 | src/pages/FilePage.cpp 39 | src/pages/HomePage.cpp 40 | src/pages/IndexPage.cpp 41 | src/pages/IndexStubPage.cpp 42 | src/pages/NotFoundPage.cpp 43 | src/pages/OpenSearchPage.cpp 44 | src/pages/PageHandler.cpp 45 | src/pages/PostPage.cpp 46 | src/pages/ProxyPage.cpp 47 | src/pages/TagSearchPage.cpp 48 | src/pages/RssPage.cpp 49 | src/pages/SavePage.cpp 50 | src/pages/Styler.cpp 51 | src/pages/UrlHandler.cpp 52 | 53 | src/parsing/OpenSearchDescription.cpp 54 | src/parsing/pugixml.cpp #Remove from project? 55 | src/parsing/Rss.cpp 56 | 57 | #src/server/ArgsParsing.cpp 58 | src/server/PocoServer.cpp 59 | 60 | src/system/TimeHandling.cpp 61 | 62 | src/main.cpp 63 | ) 64 | 65 | find_package(Poco REQUIRED NetSSL Net JSON XML Crypto) 66 | include_directories( Poco_INCLUDE_DIRS ) 67 | set( POCO_LINKS Poco_NetSSL_LIBRARY Poco_Net_LIBRARY Poco_JSON_LIBRARY Poco_XML_LIBRARY Poco_Crypto_LIBRARY ) 68 | 69 | if( NOT Poco_FOUND ) 70 | message( FATAL_ERROR "Could not find Poco" ) 71 | endif() 72 | 73 | if( UNIX ) 74 | set(THUMB_SOURCES src/system/Thumbnailer-kde.cpp) 75 | find_package(Qt5Core REQUIRED) 76 | find_package(Qt5Gui REQUIRED) 77 | set(CMAKE_AUTOMOC ON) 78 | 79 | find_package(KF5KIO REQUIRED) 80 | set(SYSTEM_LINKS Qt5::Core Qt5::Gui KF5::KIOCore KF5::KIOFileWidgets KF5::KIOWidgets KF5::KIONTLM) 81 | message( WARNING "Using KDE for thumbnailing" ) 82 | add_definitions( -DLINUX ) 83 | add_definitions( -DUSES_QT ) 84 | 85 | #TODO: Find this path 86 | include_directories( /usr/include/KF5/KIOWidgets/kio/ ) 87 | elseif( WIN32 ) 88 | set(THUMB_SOURCES src/system/Thumbnailer-windows.cpp) 89 | set(SYSTEM_LINKS -lShell32 -lUuid -lGdi32 -lOle32 -lWindowscodecs -lboost_system-mt -lboost_filesystem-mt) 90 | #TODO: find boost 91 | else() 92 | set(THUMB_SOURCES src/system/Thumbnailer-fallback.cpp) 93 | message( WARNING "Using null implementation of thumbnail" ) 94 | endif() 95 | 96 | 97 | 98 | add_executable(BooruSurfer2 ${SOURCES} ${THUMB_SOURCES} ) 99 | target_link_libraries(BooruSurfer2 -ljansson -lpng -lsqlite3 -llzma -lmyhtml_static -lpugixml ${Poco_LIBRARIES} ${SYSTEM_LINKS}) 100 | 101 | # C++14 102 | set_property(TARGET BooruSurfer2 PROPERTY CXX_STANDARD 17) 103 | set_property(TARGET BooruSurfer2 PROPERTY CXX_STANDARD_REQUIRED ON) 104 | 105 | if( WIN32 ) 106 | target_compile_definitions(BooruSurfer2 PUBLIC POCO_WIN32_UTF8) 107 | endif() 108 | -------------------------------------------------------------------------------- /src/pages/ProxyPage.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include 18 | 19 | #include "ProxyPage.hpp" 20 | 21 | #include "../exceptions/utils.hpp" 22 | 23 | #include "../api/Api.hpp" 24 | #include "../api/ApiHandler.hpp" 25 | 26 | #include "../system/Thumbnailer.hpp" 27 | 28 | #include 29 | #include 30 | #include 31 | #include 32 | 33 | using namespace std; 34 | 35 | struct RequestReader : public FilePage::StreamReader{ 36 | unique_ptr session; 37 | RequestReader( Api::UrlResponse response ) 38 | : StreamReader( response.second ), session( std::move( response.first ) ) 39 | { } 40 | }; 41 | 42 | ProxyPage::Parameters ProxyPage::parseParameters( APage::Arguments args ){ 43 | require( args.size() == 3, "Wrong amount of arguments" ); 44 | 45 | auto pos1 = args[2].find_first_of( " " ); 46 | auto pos2 = args[2].find_first_of( " ", pos1+1 ); 47 | if( pos1 == string::npos || pos2 == string::npos ) 48 | throw runtime_error( "parsing failed" ); 49 | 50 | string site = args[2].substr( 0, pos1 ); 51 | int id = getInt( args[2].substr( pos1 + 1, pos2-pos1-1 ), "Not a valid id" ); 52 | 53 | 54 | //TODO: use the filename to detect image size 55 | auto level = Image::from_string( args[1] ); 56 | 57 | return { site, id, level }; 58 | } 59 | 60 | //TODO: can we make Api const here? 61 | FilePage::Result ProxyPage::getImage( Api& api, const Post& post, const Image& img ) const{ 62 | //Determine file extension from url, which may contain arguments 63 | auto end = img.url.find( "?" ); 64 | auto start = img.url.rfind( ".", end ); 65 | auto ext = img.url.substr( start+1, end - start - 1 ); 66 | 67 | if( img.isLocal() ) 68 | return { unique_ptr( new FileReader( img.localPath() ) ), ext }; 69 | else{ 70 | auto reader = unique_ptr( 71 | new RequestReader( api.getFromUrl( img.url, { { "Referer", api.original_post_url( post.id ) } } ) ) 72 | ); 73 | return { std::move(reader), ext }; 74 | } 75 | } 76 | 77 | FilePage::Result ProxyPage::getReader( APage::Arguments args ) const{ 78 | auto input = parseParameters( args ); 79 | Api& api = ApiHandler::get_instance()->get_by_shorthand( input.site ); 80 | auto post = api.get_post( input.id, input.level ); 81 | Image img = post.get_image_size( input.level ); 82 | 83 | //Try to generate local high-res thumbnail 84 | if( input.level == Image::THUMB && post.saved ){ 85 | img = post.get_image_size( Image::ORIGINAL ); 86 | if( img.isLocal() ){ 87 | auto thumbnail = get_thumbnail( img.localPath() ); 88 | if( thumbnail.size() > 0 ) 89 | return { unique_ptr( new StringReader( thumbnail ) ), "bmp" }; 90 | } 91 | } 92 | 93 | return getImage( api, post, img ); 94 | } 95 | -------------------------------------------------------------------------------- /src/pages/FilePage.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include "FilePage.hpp" 18 | 19 | #include 20 | #include 21 | 22 | using namespace std; 23 | 24 | 25 | FilePage::FileReader::FileReader( std::string path ) 26 | : FilePage::StreamReader( fs ) 27 | , fs( path, std::fstream::in | std::fstream::binary ) 28 | { } //TODO: Check if file exists 29 | 30 | 31 | FilePage::StringReader::StringReader( const std::string& contents ) 32 | : FilePage::StreamReader( is ) 33 | , is( contents ) 34 | { } 35 | 36 | FilePage::FilePage(){ 37 | //Images 38 | mimes[ "bmp" ] = "image/x-windows-bmp"; 39 | mimes[ "jpg" ] = "image/jpeg"; 40 | mimes[ "jpeg" ] = "image/jpeg"; 41 | mimes[ "png" ] = "image/png"; 42 | mimes[ "apng" ] = "image/png"; 43 | mimes[ "tif" ] = "image/tiff"; 44 | mimes[ "tiff" ] = "image/tiff"; 45 | mimes[ "gif" ] = "image/gif"; 46 | mimes[ "webp" ] = "image/webp"; 47 | mimes[ "svg" ] = "image/svg+xml"; 48 | 49 | //Animations/movies 50 | mimes[ "swf" ] = "application/x-shockwave-flash"; 51 | mimes[ "flv" ] = "video/x-flv"; 52 | mimes[ "mp3" ] = "audio/mpeg"; 53 | mimes[ "mp4" ] = "video/mp4"; 54 | mimes[ "mkv" ] = "video/x-matroska"; 55 | mimes[ "mka" ] = "audio/x-matroska"; 56 | mimes[ "webm" ] = "video/webm"; 57 | 58 | //Web related 59 | mimes[ "js" ] = "application/x-javascript"; 60 | mimes[ "html" ] = "text/html"; 61 | mimes[ "xhtml" ] = "application/xhtml+xml"; 62 | mimes[ "css" ] = "text/css"; 63 | } 64 | 65 | FilePage::Result FilePage::getReader( vector args ) const{ 66 | //Rebuild the filepath, as it was split apart 67 | auto add_dir = [](string sum, string add){ return ( add != ".." ) ? sum + "/" + add : ""; }; 68 | string filepath = accumulate( args.begin()+1, args.end(), string("resources"), add_dir ); 69 | 70 | //Get file extension, using the solution by graphitemaster: 71 | // http://stackoverflow.com/questions/51949/how-to-get-file-extension-from-string-in-c 72 | string ext = ""; 73 | auto pos = filepath.find_last_of( "." ); 74 | if( pos != string::npos ) 75 | ext = filepath.substr( pos + 1 ); 76 | cout << filepath << "\n"; 77 | 78 | return make_pair( unique_ptr( new FileReader( filepath ) ), ext ); 79 | } 80 | 81 | unique_ptr FilePage::serve( APage::Arguments args, std::vector
    & headers ) const{ 82 | auto result = getReader( args ); 83 | headers.push_back( header( "Content-Type", get_mime( result.second ) ) ); 84 | headers.push_back( header( "Cache-Control", "max-age=31536000" ) ); 85 | return std::move( result.first ); 86 | } 87 | 88 | string FilePage::get_mime( string ext ) const{ 89 | unordered_map::const_iterator got = mimes.find( ext ); 90 | if( got != mimes.end() ) 91 | return got->second; 92 | else 93 | return "text/plain"; 94 | } 95 | 96 | -------------------------------------------------------------------------------- /src/pages/png++/rgba_pixel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007,2008 Alex Shulgin 3 | * 4 | * This file is part of png++ the C++ wrapper for libpng. PNG++ is free 5 | * software; the exact copying conditions are as follows: 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 23 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 25 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef PNGPP_RGBA_PIXEL_HPP_INCLUDED 32 | #define PNGPP_RGBA_PIXEL_HPP_INCLUDED 33 | 34 | #include "types.hpp" 35 | #include "pixel_traits.hpp" 36 | 37 | namespace png 38 | { 39 | 40 | /** 41 | * \brief RGBA pixel type. 42 | */ 43 | template< typename T > 44 | struct basic_rgba_pixel 45 | { 46 | typedef pixel_traits< basic_rgba_pixel< T > > traits; 47 | 48 | /** 49 | * \brief Default constructor. Initializes all components 50 | * with zeros. 51 | */ 52 | basic_rgba_pixel() 53 | : red(0), green(0), blue(0), alpha(0) 54 | { 55 | } 56 | 57 | /** 58 | * \brief Constructs rgba_pixel object from \a red, \a green, 59 | * \a blue and \a alpha components passed as parameters. 60 | * Alpha defaults to full opacity. 61 | */ 62 | basic_rgba_pixel(T red, T green, T blue, 63 | T alpha = traits::get_alpha_filler()) 64 | : red(red), green(green), blue(blue), alpha(alpha) 65 | { 66 | } 67 | 68 | T red; 69 | T green; 70 | T blue; 71 | T alpha; 72 | }; 73 | 74 | /** 75 | * The 8-bit RGBA pixel type. 76 | */ 77 | typedef basic_rgba_pixel< byte > rgba_pixel; 78 | 79 | /** 80 | * The 16-bit RGBA pixel type. 81 | */ 82 | typedef basic_rgba_pixel< uint_16 > rgba_pixel_16; 83 | 84 | /** 85 | * \brief Pixel traits specialization for basic_rgba_pixel. 86 | */ 87 | template< typename T > 88 | struct pixel_traits< basic_rgba_pixel< T > > 89 | : basic_pixel_traits< basic_rgba_pixel< T >, T, color_type_rgba >, 90 | basic_alpha_pixel_traits< T > 91 | { 92 | }; 93 | 94 | } // namespace png 95 | 96 | #endif // PNGPP_RGBA_PIXEL_HPP_INCLUDED 97 | -------------------------------------------------------------------------------- /src/parsing/StringViewUtils.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #ifndef STRING_VIEW_UTILS_HPP 18 | #define STRING_VIEW_UTILS_HPP 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | 28 | inline bool starts_with( std::string_view input, std::string_view match ){ 29 | if( input.length() >= match.length() ) 30 | return input.substr( 0, match.length() ) == match; 31 | return false; 32 | } 33 | inline bool ends_with( std::string_view input, std::string_view match ){ 34 | if( input.length() >= match.length() ) 35 | return input.substr( input.size() - match.length() ) == match; 36 | return false; 37 | } 38 | 39 | inline std::pair splitAt( std::string_view str, char splitter ){ 40 | auto pos = str.find( splitter ); 41 | if( pos == std::string_view::npos ) 42 | return { str, {} }; 43 | else 44 | return { str.substr( 0, pos ), str.substr( pos+1 ) }; 45 | } 46 | 47 | inline std::vector splitAllOn( std::string_view str, char splitter ){ 48 | std::vector splits; 49 | 50 | size_t last=0, pos = 0; 51 | while( (pos = str.find(splitter, last)) != std::string_view::npos ){ 52 | splits.push_back( str.substr( last, pos-last ) ); 53 | last = pos+1; 54 | } 55 | splits.push_back( str.substr( last ) ); 56 | 57 | return splits; 58 | } 59 | inline void removeEmpty( std::vector& list ){ 60 | list.erase( std::remove_if( list.begin(), list.end(), [](auto& item){ return item.empty(); } ), list.end() ); 61 | } 62 | 63 | 64 | inline int parseInt( std::string_view input, int fallback ){ 65 | int value = 0; 66 | auto result = std::from_chars( input.begin(), input.end(), value, 10 ); 67 | return result.ptr == input.begin() ? fallback : value; 68 | } 69 | 70 | inline double parseDouble( std::string_view input, double fallback ){ 71 | //TODO: Avoid string conversion 72 | //TODO: 4.7 got parsed as "4" ! 73 | try 74 | { return std::stod(std::string(input)); } 75 | catch(...) 76 | { return fallback; } 77 | } 78 | 79 | 80 | 81 | inline std::string_view removePrefix( std::string_view str, std::string_view prefix ){ 82 | if( !starts_with( str, prefix ) ) 83 | throw std::logic_error( std::string(str) + " does not start with " + std::string(prefix) ); 84 | return str.substr( prefix.size() );; 85 | } 86 | inline std::string_view removePostfix( std::string_view str, std::string_view postfix ){ 87 | if( !ends_with( str, postfix ) ) 88 | throw std::logic_error( std::string(str) + " does not end with " + std::string(postfix) ); 89 | return str.substr( str.size() - postfix.size() ); 90 | } 91 | inline std::string_view trim( std::string_view str ){ 92 | auto first = str.find_first_not_of( ' ' ); 93 | auto last = str.find_last_not_of( ' ' ); 94 | auto chars_removed = first + (str.size()-last-1); 95 | return str.substr( first, str.size() - chars_removed ); 96 | } 97 | 98 | 99 | 100 | #endif 101 | 102 | -------------------------------------------------------------------------------- /src/pages/png++/pixel_traits.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007,2008 Alex Shulgin 3 | * 4 | * This file is part of png++ the C++ wrapper for libpng. PNG++ is free 5 | * software; the exact copying conditions are as follows: 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 23 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 25 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef PNGPP_PIXEL_TRAITS_HPP_INCLUDED 32 | #define PNGPP_PIXEL_TRAITS_HPP_INCLUDED 33 | 34 | #include 35 | #include "types.hpp" 36 | 37 | namespace png 38 | { 39 | 40 | /** 41 | * \brief Pixel traits class template. 42 | * 43 | * Provides information about pixel color type and components bit depth. 44 | * Not implemented--see specializations. 45 | * 46 | * \see pixel_traits, pixel_traits 47 | */ 48 | template< typename pixel > struct pixel_traits; 49 | 50 | /** 51 | * \brief Basic pixel traits class template. 52 | * 53 | * Provides common implementation for various pixel_traits<> 54 | * specializations. 55 | */ 56 | template< typename pixel, 57 | typename component, 58 | color_type pixel_color_type, 59 | size_t channels = sizeof(pixel) / sizeof(component), 60 | size_t bit_depth = std::numeric_limits< component >::digits > 61 | struct basic_pixel_traits 62 | { 63 | typedef pixel pixel_type; 64 | typedef component component_type; 65 | 66 | static color_type get_color_type() 67 | { 68 | return pixel_color_type; 69 | } 70 | static size_t get_channels() 71 | { 72 | return channels; 73 | } 74 | static size_t get_bit_depth() 75 | { 76 | return bit_depth; 77 | } 78 | }; 79 | 80 | /** 81 | * \brief Basic pixel traits class template for pixels with alpha 82 | * channel. 83 | */ 84 | template< typename component > 85 | struct basic_alpha_pixel_traits 86 | { 87 | /** 88 | * \brief Returns the default alpha channel filler for full 89 | * opacity. 90 | */ 91 | static component get_alpha_filler() 92 | { 93 | return std::numeric_limits< component >::max(); 94 | } 95 | }; 96 | 97 | } // namespace png 98 | 99 | #endif // PNGPP_PIXEL_TRAITS_HPP_INCLUDED 100 | -------------------------------------------------------------------------------- /src/pages/png++/index_pixel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007,2008 Alex Shulgin 3 | * 4 | * This file is part of png++ the C++ wrapper for libpng. PNG++ is free 5 | * software; the exact copying conditions are as follows: 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 23 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 25 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef PNGPP_INDEX_PIXEL_HPP_INCLUDED 32 | #define PNGPP_INDEX_PIXEL_HPP_INCLUDED 33 | 34 | #include "types.hpp" 35 | #include "packed_pixel.hpp" 36 | #include "pixel_traits.hpp" 37 | 38 | namespace png 39 | { 40 | 41 | /** 42 | * \brief The 8-bit Indexed (colormap) pixel type. 43 | */ 44 | class index_pixel 45 | { 46 | public: 47 | index_pixel(byte index = 0) 48 | : m_index(index) 49 | { 50 | } 51 | 52 | operator byte() const 53 | { 54 | return m_index; 55 | } 56 | 57 | private: 58 | byte m_index; 59 | }; 60 | 61 | /** 62 | * \brief The packed indexed pixel class template. The available 63 | * specializations are for 1-, 2- and 4-bit pixels. 64 | */ 65 | template< size_t bits > 66 | class packed_index_pixel 67 | : public packed_pixel< bits > 68 | { 69 | public: 70 | packed_index_pixel(byte value = 0) 71 | : packed_pixel< bits >(value) 72 | { 73 | } 74 | }; 75 | 76 | /** 77 | * \brief The 1-bit Indexed pixel type. 78 | */ 79 | typedef packed_index_pixel< 1 > index_pixel_1; 80 | 81 | /** 82 | * \brief The 1-bit Indexed pixel type. 83 | */ 84 | typedef packed_index_pixel< 2 > index_pixel_2; 85 | 86 | /** 87 | * \brief The 1-bit Indexed pixel type. 88 | */ 89 | typedef packed_index_pixel< 4 > index_pixel_4; 90 | 91 | /** 92 | * \brief Pixel traits specialization for index_pixel. 93 | */ 94 | template<> 95 | struct pixel_traits< index_pixel > 96 | : basic_pixel_traits< index_pixel, byte, color_type_palette > 97 | { 98 | }; 99 | 100 | /** 101 | * \brief Pixel traits specialization for packed_index_pixel. 102 | */ 103 | template< size_t bits > 104 | struct pixel_traits< packed_index_pixel< bits > > 105 | : basic_pixel_traits< packed_index_pixel< bits >, byte, 106 | color_type_palette, /* channels = */ 1, bits > 107 | { 108 | }; 109 | 110 | } // namespace png 111 | 112 | #endif // PNGPP_INDEX_PIXEL_HPP_INCLUDED 113 | -------------------------------------------------------------------------------- /src/server/ArgsParsing.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "Server.hpp" 24 | #include "../api/ApiHandler.hpp" 25 | #include "../db/Booru.hpp" 26 | #include "../pages/APage.hpp" 27 | #include "../pages/PageHandler.hpp" 28 | 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | 35 | #ifdef WIN32 36 | #include //TODO: Windows only 37 | #endif 38 | 39 | using namespace Poco; 40 | using namespace Poco::Net; 41 | using namespace std; 42 | 43 | string Server::remove_reserved( const string& input ){ 44 | string output = input; 45 | boost::replace_all( output, "$", "%24" ); 46 | boost::replace_all( output, "&", "%26" ); 47 | boost::replace_all( output, "+", "%2B" ); 48 | boost::replace_all( output, ",", "%2C" ); 49 | boost::replace_all( output, "/", "%2F" ); 50 | boost::replace_all( output, ":", "%3A" ); 51 | boost::replace_all( output, ";", "%3B" ); 52 | boost::replace_all( output, "=", "%3D" ); 53 | boost::replace_all( output, "?", "%3F" ); 54 | boost::replace_all( output, "@", "%40" ); 55 | return output; 56 | } 57 | string Server::encode_str( const string& input ){ 58 | string output, reserved; //TODO: reserved, wtf? 59 | URI::encode( input, reserved, output ); 60 | return output; 61 | } 62 | string Server::unencode_str( const string& input ){ 63 | string output; 64 | string temp = input; 65 | boost::replace_all( temp, "+", "%20" ); 66 | URI::decode( temp, output ); 67 | return output; 68 | } 69 | 70 | class RequestHandler : public HTTPRequestHandler { 71 | public: 72 | virtual void handleRequest( HTTPServerRequest& req, HTTPServerResponse& response ) override { 73 | #ifdef WIN32 74 | CoInitialize( nullptr ); //TODO: Windows only 75 | //TODO: How are thread handled? Should only be called once per thread 76 | #endif 77 | 78 | PageHandler pages; 79 | 80 | //Split on '/' and remove empty parts 81 | vector args; 82 | boost::split( args, req.getURI(), boost::is_any_of( "/" ) ); //TODO: avoid is_any_of() ? 83 | args.erase( remove_if( args.begin(), args.end(), [](string arg){ return arg.empty(); } ), args.end() ); 84 | 85 | for( auto& arg : args ) 86 | arg = Server::unencode_str( arg ); 87 | 88 | //Process page 89 | if( args.size() == 0 ) 90 | pages.get_root()->handleRequest( args, response ); 91 | else 92 | pages.get( args[0] )->handleRequest( args, response ); 93 | } 94 | }; 95 | 96 | class RequestHandlerFactory : public HTTPRequestHandlerFactory { 97 | public: 98 | virtual HTTPRequestHandler* createRequestHandler( const HTTPServerRequest& request ) override{ 99 | return new RequestHandler; 100 | } 101 | }; 102 | 103 | 104 | int Server::main( const vector& unknown ){ 105 | HTTPServer s( new RequestHandlerFactory, 8000 ); 106 | 107 | s.start(); 108 | waitForTerminationRequest(); 109 | s.stop(); 110 | 111 | return Application::EXIT_OK; 112 | } 113 | 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /src/server/PocoServer.cpp: -------------------------------------------------------------------------------- 1 | /* This file is part of BooruSurfer2. 2 | 3 | BooruSurfer2 is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | BooruSurfer2 is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with BooruSurfer2. If not, see . 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include "Server.hpp" 24 | #include "../api/ApiHandler.hpp" 25 | #include "../db/Booru.hpp" 26 | #include "../pages/APage.hpp" 27 | #include "../pages/PageHandler.hpp" 28 | 29 | #include 30 | #include 31 | 32 | #include 33 | #include 34 | 35 | #ifdef WIN32 36 | #include //TODO: Windows only 37 | #endif 38 | 39 | using namespace Poco; 40 | using namespace Poco::Net; 41 | using namespace std; 42 | 43 | string Server::remove_reserved( const string& input ){ 44 | string output = input; 45 | boost::replace_all( output, "$", "%24" ); 46 | boost::replace_all( output, "&", "%26" ); 47 | boost::replace_all( output, "+", "%2B" ); 48 | boost::replace_all( output, ",", "%2C" ); 49 | boost::replace_all( output, "/", "%2F" ); 50 | boost::replace_all( output, ":", "%3A" ); 51 | boost::replace_all( output, ";", "%3B" ); 52 | boost::replace_all( output, "=", "%3D" ); 53 | boost::replace_all( output, "?", "%3F" ); 54 | boost::replace_all( output, "@", "%40" ); 55 | return output; 56 | } 57 | string Server::encode_str( const string& input ){ 58 | string output, reserved; //TODO: reserved, wtf? 59 | URI::encode( input, reserved, output ); 60 | return output; 61 | } 62 | string Server::unencode_str( const string& input ){ 63 | string output; 64 | string temp = input; 65 | boost::replace_all( temp, "+", "%20" ); 66 | URI::decode( temp, output ); 67 | return output; 68 | } 69 | 70 | class RequestHandler : public HTTPRequestHandler { 71 | public: 72 | virtual void handleRequest( HTTPServerRequest& req, HTTPServerResponse& response ) override { 73 | #ifdef WIN32 74 | CoInitialize( nullptr ); //TODO: Windows only 75 | //TODO: How are thread handled? Should only be called once per thread 76 | #endif 77 | 78 | PageHandler pages; 79 | 80 | //Split on '/' and remove empty parts 81 | vector args; 82 | boost::split( args, req.getURI(), boost::is_any_of( "/" ) ); //TODO: avoid is_any_of() ? 83 | args.erase( remove_if( args.begin(), args.end(), [](string arg){ return arg.empty(); } ), args.end() ); 84 | 85 | for( auto& arg : args ) 86 | arg = Server::unencode_str( arg ); 87 | 88 | //Process page 89 | if( args.size() == 0 ) 90 | pages.get_root()->handleRequest( args, response ); 91 | else 92 | pages.get( args[0] )->handleRequest( args, response ); 93 | } 94 | }; 95 | 96 | class RequestHandlerFactory : public HTTPRequestHandlerFactory { 97 | public: 98 | virtual HTTPRequestHandler* createRequestHandler( const HTTPServerRequest& request ) override{ 99 | return new RequestHandler; 100 | } 101 | }; 102 | 103 | 104 | int Server::main( const vector& unknown ){ 105 | HTTPServer s( new RequestHandlerFactory, 8000 ); 106 | 107 | s.start(); 108 | waitForTerminationRequest(); 109 | s.stop(); 110 | 111 | return Application::EXIT_OK; 112 | } 113 | 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /src/db/Booru.hpp: -------------------------------------------------------------------------------- 1 | /* This file is part of rss2rss. 2 | 3 | rss2rss is free software: you can redistribute it and/or modify 4 | it under the terms of the GNU General Public License as published by 5 | the Free Software Foundation, either version 3 of the License, or 6 | (at your option) any later version. 7 | 8 | rss2rss is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | GNU General Public License for more details. 12 | 13 | You should have received a copy of the GNU General Public License 14 | along with rss2rss. If not, see . 15 | */ 16 | 17 | #ifndef BOORU_HPP 18 | #define BOORU_HPP 19 | 20 | #include "Database.hpp" 21 | #include "Statement.hpp" 22 | 23 | #include "../objects/Post.hpp" 24 | #include "../objects/Note.hpp" 25 | #include "../objects/Tag.hpp" 26 | #include "../objects/Index.hpp" 27 | 28 | #include 29 | #include 30 | #include 31 | 32 | void resetDatabaseConnections(); 33 | 34 | class Booru{ 35 | private: 36 | std::string site; 37 | 38 | void saveToDb( const Note& item ); 39 | void saveToDb( const Tag& item ); 40 | void saveToDb( const Post& item ); 41 | 42 | template 43 | struct CacheItem{ 44 | T value; 45 | bool saved; 46 | CacheItem( T value, bool saved ) : value(value), saved(saved) { } 47 | }; 48 | 49 | template 50 | class Cache{ 51 | private: 52 | std::mutex lock; 53 | std::vector> items; 54 | 55 | public: 56 | bool get( T& find ){ 57 | std::lock_guard locker( lock ); 58 | for( auto& item : items ) 59 | if( item.value.id == find.id ){ 60 | find = item.value; 61 | return true; 62 | } 63 | return false; 64 | } 65 | 66 | void insert( T& item, bool saved ){ 67 | std::lock_guard locker( lock ); 68 | items.emplace_back( item, saved ); 69 | } 70 | 71 | void replace( const T& t, bool saved = false ){ 72 | std::lock_guard locker( lock ); 73 | for( auto& item : items ) 74 | if( item.value.id == t.id ){ 75 | item.value = t; 76 | item.saved = saved; 77 | } 78 | } 79 | 80 | void flush( Booru& booru ){ 81 | std::lock_guard locker( lock ); 82 | 83 | //Find all items to save 84 | std::vector*> saved; 85 | for( auto& item : items ) 86 | if( !item.saved ) 87 | saved.emplace_back( &item ); 88 | 89 | //Save items, but reduce transactions as much as possible 90 | if( saved.size() == 0 ) return; 91 | if( saved.size() == 1 ) booru.saveToDb( saved[0]->value ); 92 | else{ 93 | auto batch = booru.beginBatch(); 94 | for( auto& cache : saved ) 95 | booru.saveToDb( cache->value ); 96 | batch.close(); 97 | } 98 | 99 | //Commit successful, apply changes 100 | for( auto& cache : saved ) 101 | cache->saved = true; 102 | } 103 | }; 104 | 105 | Cache posts; 106 | Cache tags; 107 | Cache notes; 108 | 109 | Transaction beginBatch(); 110 | 111 | public: 112 | Booru( std::string site ); 113 | 114 | bool load( Note& n ); 115 | bool load( Post& p ); 116 | bool load( Post& p, Image::Size level ); 117 | bool load( Tag& p ); 118 | bool load( Index& index, IndexId id ); 119 | 120 | void save( Note& n ); 121 | void save( Post& p ); 122 | void save( Tag& p ); 123 | void save( Index& index ); 124 | 125 | Index iteratePosts( IndexId id ); 126 | 127 | std::vector searchTags( std::string query ); 128 | 129 | void flushNotes(){ notes.flush( *this ); } 130 | void flushPosts(){ posts.flush( *this ); } 131 | void flushTags (){ tags .flush( *this ); } 132 | }; 133 | 134 | #endif 135 | 136 | -------------------------------------------------------------------------------- /src/pages/png++/gray_pixel.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007,2008 Alex Shulgin 3 | * 4 | * This file is part of png++ the C++ wrapper for libpng. PNG++ is free 5 | * software; the exact copying conditions are as follows: 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions are met: 9 | * 10 | * 1. Redistributions of source code must retain the above copyright notice, 11 | * this list of conditions and the following disclaimer. 12 | * 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 17 | * 3. The name of the author may not be used to endorse or promote products 18 | * derived from this software without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 23 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 25 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | #ifndef PNGPP_GRAY_PIXEL_HPP_INCLUDED 32 | #define PNGPP_GRAY_PIXEL_HPP_INCLUDED 33 | 34 | #include "types.hpp" 35 | #include "packed_pixel.hpp" 36 | #include "pixel_traits.hpp" 37 | 38 | namespace png 39 | { 40 | 41 | /** 42 | * \brief The 8-bit Grayscale pixel type. 43 | */ 44 | typedef byte gray_pixel; 45 | 46 | /** 47 | * \brief The 16-bit Grayscale pixel type. 48 | */ 49 | typedef uint_16 gray_pixel_16; 50 | 51 | /** 52 | * \brief The packed gray pixel class template. The available 53 | * specializations are for 1-, 2- and 4-bit pixels. 54 | */ 55 | template< size_t bits > 56 | class packed_gray_pixel 57 | : public packed_pixel< bits > 58 | { 59 | public: 60 | packed_gray_pixel(byte value = 0) 61 | : packed_pixel< bits >(value) 62 | { 63 | } 64 | }; 65 | 66 | /** 67 | * \brief The 1-bit Grayscale pixel type. 68 | */ 69 | typedef packed_gray_pixel< 1 > gray_pixel_1; 70 | 71 | /** 72 | * \brief The 2-bit Grayscale pixel type. 73 | */ 74 | typedef packed_gray_pixel< 2 > gray_pixel_2; 75 | 76 | /** 77 | * \brief The 4-bit Grayscale pixel type. 78 | */ 79 | typedef packed_gray_pixel< 4 > gray_pixel_4; 80 | 81 | /** 82 | * \brief Pixel traits specialization for gray_pixel. 83 | */ 84 | template<> 85 | struct pixel_traits< gray_pixel > 86 | : basic_pixel_traits< gray_pixel, byte, color_type_gray > 87 | { 88 | }; 89 | 90 | /** 91 | * \brief Pixel traits specialization for gray_pixel_16. 92 | */ 93 | template<> 94 | struct pixel_traits< gray_pixel_16 > 95 | : basic_pixel_traits< gray_pixel_16, uint_16, color_type_gray > 96 | { 97 | }; 98 | 99 | /** 100 | * \brief Pixel traits specialization for packed_gray_pixel. 101 | */ 102 | template< size_t bits > 103 | struct pixel_traits< packed_gray_pixel< bits > > 104 | : basic_pixel_traits< packed_gray_pixel< bits >, byte, 105 | color_type_gray, /* channels = */ 1, bits > 106 | { 107 | }; 108 | 109 | } // namespace png 110 | 111 | #endif // PNGPP_GRAY_PIXEL_HPP_INCLUDED 112 | --------------------------------------------------------------------------------