diff --git a/install/sql/mysql.sql b/install/sql/mysql.sql index 4a164a58d..1317a99ac 100644 --- a/install/sql/mysql.sql +++ b/install/sql/mysql.sql @@ -29,7 +29,6 @@ DROP TABLE IF EXISTS `bb_bt_last_torstat`; DROP TABLE IF EXISTS `bb_bt_last_userstat`; DROP TABLE IF EXISTS `bb_bt_torhelp`; DROP TABLE IF EXISTS `bb_bt_torrents`; -DROP TABLE IF EXISTS `bb_bt_torrents_del`; DROP TABLE IF EXISTS `bb_bt_torstat`; DROP TABLE IF EXISTS `bb_bt_tor_dl_stat`; DROP TABLE IF EXISTS `bb_bt_tracker`; @@ -75,11 +74,6 @@ DROP TABLE IF EXISTS `bb_words`; DROP TABLE IF EXISTS `buf_last_seeder`; DROP TABLE IF EXISTS `buf_topic_view`; DROP TABLE IF EXISTS `sph_counter`; -DROP TABLE IF EXISTS `xbt_announce_log`; -DROP TABLE IF EXISTS `xbt_config`; -DROP TABLE IF EXISTS `xbt_deny_from_hosts`; -DROP TABLE IF EXISTS `xbt_files_users`; -DROP TABLE IF EXISTS `xbt_scrape_log`; -- -- Структура таблицы `bb_ads` @@ -379,20 +373,6 @@ CREATE TABLE IF NOT EXISTS `bb_bt_torrents` ( -- -------------------------------------------------------- --- --- Структура таблицы `bb_bt_torrents_del` --- - -CREATE TABLE IF NOT EXISTS `bb_bt_torrents_del` ( - `topic_id` mediumint(8) unsigned NOT NULL, - `info_hash` varbinary(20) NOT NULL, - `is_del` tinyint(4) NOT NULL DEFAULT '1', - `dl_percent` tinyint(4) NOT NULL DEFAULT '100', - PRIMARY KEY (`topic_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - -- -- Структура таблицы `bb_bt_torstat` -- @@ -446,7 +426,6 @@ CREATE TABLE IF NOT EXISTS `bb_bt_tracker` ( `up_add` bigint(20) unsigned NOT NULL DEFAULT '0', `down_add` bigint(20) unsigned NOT NULL DEFAULT '0', `update_time` int(11) NOT NULL DEFAULT '0', - `xbt_error` varchar(200) DEFAULT NULL, `ul_gdc` bigint(20) unsigned NOT NULL DEFAULT '0', `ul_gdc_c` mediumint(9) unsigned NOT NULL DEFAULT '0', `ul_16k_c` mediumint(9) unsigned NOT NULL DEFAULT '0', @@ -664,7 +643,6 @@ INSERT INTO `bb_config` VALUES ('report_hack_count', '0'); INSERT INTO `bb_config` VALUES ('report_notify', '0'); INSERT INTO `bb_config` VALUES ('report_list_admin', '0'); INSERT INTO `bb_config` VALUES ('report_new_window', '0'); -INSERT INTO `bb_config` VALUES ('torrent_pass_private_key', 'вставить_из_конфига_XBTT'); INSERT INTO `bb_config` VALUES ('cron_enabled', '1'); INSERT INTO `bb_config` VALUES ('cron_check_interval', '300'); INSERT INTO `bb_config` VALUES ('reports_enabled', '1'); @@ -1006,7 +984,7 @@ CREATE TABLE IF NOT EXISTS `bb_posts_text` ( -- Дамп данных таблицы `bb_posts_text` -- -INSERT INTO `bb_posts_text` VALUES (1, '[list]\n[*]Переделан поиск по топикам с выбором типа [none, mysql, sphinx] (только в tracker.php)\n[*]Удалены bbcode_uid и переход на class.bbcode\n[*]Изменён метод и способ кеширования (memcache, sqlite, db_sqlite, redis, eaccelerator, apc, xcache, filecache)\n[*]Изменён способ подключения к БД и отказ от глобальной переменной $db\n[*]Улучшенный дебагер\n[*]Полностью переписан и упрощен файл регистрации\n[*]Переписана капча (в том числе при быстром ответе у гостя)\n[*]Добавлена возможность выбора типа анонсера (xbt или php)\n[*]Удаление файлов torrent.php и torstatus.php и перенос их функций в ajax\n[*]Ajax цитирование, изменение, редактирование, удаление сообщений\n[/list]'); +INSERT INTO `bb_posts_text` VALUES (1, '[list]\n[*]Переделан поиск по топикам с выбором типа [none, mysql, sphinx] (только в tracker.php)\n[*]Удалены bbcode_uid и переход на class.bbcode\n[*]Изменён метод и способ кеширования (memcache, sqlite, db_sqlite, redis, eaccelerator, apc, xcache, filecache)\n[*]Изменён способ подключения к БД и отказ от глобальной переменной $db\n[*]Улучшенный дебагер\n[*]Полностью переписан и упрощен файл регистрации\n[*]Переписана капча (в том числе при быстром ответе у гостя)\n[*]Удаление файлов torrent.php и torstatus.php и перенос их функций в ajax\n[*]Ajax цитирование, изменение, редактирование, удаление сообщений\n[/list]'); -- -------------------------------------------------------- @@ -1581,83 +1559,4 @@ CREATE TABLE IF NOT EXISTS `sph_counter` ( `counter_id` int(11) NOT NULL, `max_doc_id` int(11) NOT NULL, PRIMARY KEY (`counter_id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - --- --- Структура таблицы `xbt_announce_log` --- - -CREATE TABLE IF NOT EXISTS `xbt_announce_log` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `ipa` int(10) unsigned NOT NULL DEFAULT '0', - `port` int(11) NOT NULL DEFAULT '0', - `event` int(11) NOT NULL DEFAULT '0', - `info_hash` blob NOT NULL, - `peer_id` blob NOT NULL, - `downloaded` bigint(20) NOT NULL DEFAULT '0', - `left0` bigint(20) NOT NULL DEFAULT '0', - `uploaded` bigint(20) NOT NULL DEFAULT '0', - `uid` int(11) NOT NULL DEFAULT '0', - `mtime` int(11) NOT NULL DEFAULT '0', - PRIMARY KEY (`id`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - --- --- Структура таблицы `xbt_config` --- - -CREATE TABLE IF NOT EXISTS `xbt_config` ( - `name` varchar(255) NOT NULL DEFAULT '', - `value` varchar(255) NOT NULL DEFAULT '', - PRIMARY KEY (`name`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - --- --- Структура таблицы `xbt_deny_from_hosts` --- - -CREATE TABLE IF NOT EXISTS `xbt_deny_from_hosts` ( - `begin` int(11) NOT NULL DEFAULT '0', - `end` int(11) NOT NULL DEFAULT '0' -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - --- --- Структура таблицы `xbt_files_users` --- - -CREATE TABLE IF NOT EXISTS `xbt_files_users` ( - `fid` int(11) NOT NULL DEFAULT '0', - `uid` int(11) NOT NULL DEFAULT '0', - `active` tinyint(4) NOT NULL DEFAULT '0', - `announced` int(11) NOT NULL DEFAULT '0', - `completed` int(11) NOT NULL DEFAULT '0', - `downloaded` bigint(20) NOT NULL DEFAULT '0', - `left` bigint(20) NOT NULL DEFAULT '0', - `uploaded` bigint(20) NOT NULL DEFAULT '0', - `mtime` int(11) NOT NULL DEFAULT '0', - UNIQUE KEY `fid` (`fid`,`uid`), - KEY `uid` (`uid`) -) ENGINE=MyISAM DEFAULT CHARSET=utf8; - --- -------------------------------------------------------- - --- --- Структура таблицы `xbt_scrape_log` --- - -CREATE TABLE IF NOT EXISTS `xbt_scrape_log` ( - `id` int(11) NOT NULL AUTO_INCREMENT, - `ipa` int(11) NOT NULL DEFAULT '0', - `info_hash` blob, - `uid` int(11) NOT NULL DEFAULT '0', - `mtime` int(11) NOT NULL DEFAULT '0', - PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/install/xbt/linux/Tracker/CMakeLists.txt b/install/xbt/linux/Tracker/CMakeLists.txt deleted file mode 100644 index 93d1f9eec..000000000 --- a/install/xbt/linux/Tracker/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -cmake_minimum_required(VERSION 2.4) -set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS true) -set(CMAKE_BUILD_TYPE release) -include_directories(. ../misc) -include(CheckIncludeFileCXX) -check_include_file_cxx(sys/epoll.h HAVE_SYS_EPOLL) -if(HAVE_SYS_EPOLL) - add_definitions(-DEPOLL) -endif() -add_executable( - xbt_tracker - ../misc/sql/database.cpp - ../misc/sql/sql_query.cpp - ../misc/sql/sql_result.cpp - ../misc/bt_misc.cpp - ../misc/bvalue.cpp - ../misc/sha1.cpp - ../misc/socket.cpp - ../misc/virtual_binary.cpp - ../misc/xcc_z.cpp - config.cpp - connection.cpp - epoll.cpp - server.cpp - tcp_listen_socket.cpp - tracker_input.cpp - transaction.cpp - udp_listen_socket.cpp - "XBT Tracker.cpp" -) -target_link_libraries(xbt_tracker mysqlclient) diff --git a/install/xbt/linux/Tracker/XBT Tracker.cpp b/install/xbt/linux/Tracker/XBT Tracker.cpp deleted file mode 100644 index 9c4587ffe..000000000 --- a/install/xbt/linux/Tracker/XBT Tracker.cpp +++ /dev/null @@ -1,135 +0,0 @@ -#include "stdafx.h" -#include -#include -#include "config.h" -#include "server.h" - -std::string g_conf_file = "xbt_tracker.conf"; -const char* g_service_name = "XBT Tracker"; - -int main1() -{ - srand(static_cast(time(NULL))); - Cconfig config; - if (config.load(g_conf_file)) -#ifdef WIN32 - { - char b[MAX_PATH]; - *b = 0; - GetModuleFileName(NULL, b, MAX_PATH); - if (*b) - strrchr(b, '\\')[1] = 0; - strcat(b, "xbt_tracker.conf"); - if (config.load(b)) - std::cerr << "Unable to read " << g_conf_file << std::endl; - else - g_conf_file = b; - } -#else - std::cerr << "Unable to read " << g_conf_file << std::endl; -#endif - Cdatabase database; - try - { - if (config.m_mysql_host != "-") - database.open(config.m_mysql_host, config.m_mysql_user, config.m_mysql_password, config.m_mysql_database, true); - } - catch (Cdatabase::exception& e) - { - std::cerr << e.what() << std::endl; - return 1; - } - database.set_query_log(config.m_query_log); - return Cserver(database, config.m_mysql_table_prefix, config.m_mysql_host != "-", g_conf_file).run(); -} - -#ifdef WIN32 -static SERVICE_STATUS g_service_status; -static SERVICE_STATUS_HANDLE gh_service_status; - -void WINAPI nt_service_handler(DWORD op) -{ - switch (op) - { - case SERVICE_CONTROL_STOP: - g_service_status.dwCurrentState = SERVICE_STOP_PENDING; - SetServiceStatus(gh_service_status, &g_service_status); - Cserver::term(); - break; - } - SetServiceStatus(gh_service_status, &g_service_status); -} - -void WINAPI nt_service_main(DWORD argc, LPTSTR* argv) -{ - g_service_status.dwCheckPoint = 0; - g_service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP; - g_service_status.dwCurrentState = SERVICE_START_PENDING; - g_service_status.dwServiceSpecificExitCode = 0; - g_service_status.dwServiceType = SERVICE_WIN32_OWN_PROCESS; - g_service_status.dwWaitHint = 0; - g_service_status.dwWin32ExitCode = NO_ERROR; - if (!(gh_service_status = RegisterServiceCtrlHandler(g_service_name, nt_service_handler))) - return; - SetServiceStatus(gh_service_status, &g_service_status); - g_service_status.dwCurrentState = SERVICE_RUNNING; - SetServiceStatus(gh_service_status, &g_service_status); - main1(); - g_service_status.dwCurrentState = SERVICE_STOPPED; - SetServiceStatus(gh_service_status, &g_service_status); -} -#endif - -int main(int argc, char* argv[]) -{ -#ifdef WIN32 - if (argc >= 2) - { - if (!strcmp(argv[1], "--install")) - { - if (nt_service_install(g_service_name)) - { - std::cerr << "Failed to install service " << g_service_name << "." << std::endl; - return 1; - } - std::cout << "Service " << g_service_name << " has been installed." << std::endl; - return 0; - } - else if (!strcmp(argv[1], "--uninstall")) - { - if (nt_service_uninstall(g_service_name)) - { - std::cerr << "Failed to uninstall service " << g_service_name << "." << std::endl; - return 1; - } - std::cout << "Service " << g_service_name << " has been uninstalled." << std::endl; - return 0; - } - else if (!strcmp(argv[1], "--conf_file") && argc >= 3) - g_conf_file = argv[2]; - else - return 1; - } -#ifdef NDEBUG - SERVICE_TABLE_ENTRY st[] = - { - { "", nt_service_main }, - { NULL, NULL } - }; - if (StartServiceCtrlDispatcher(st)) - return 0; - if (GetLastError() != ERROR_CALL_NOT_IMPLEMENTED - && GetLastError() != ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) - return 1; -#endif -#else - if (argc >= 2) - { - if (!strcmp(argv[1], "--conf_file") && argc >= 3) - g_conf_file = argv[2]; - else - return 1; - } -#endif - return main1(); -} diff --git a/install/xbt/linux/Tracker/XBT Tracker.nsi b/install/xbt/linux/Tracker/XBT Tracker.nsi deleted file mode 100644 index 19b998665..000000000 --- a/install/xbt/linux/Tracker/XBT Tracker.nsi +++ /dev/null @@ -1,46 +0,0 @@ -!define VERSION "0.3.0" - -Name "XBT Tracker ${VERSION}" -Outfile "XBT_Tracker-${VERSION}.exe" -InstallDir "$PROGRAMFILES\XBT\Tracker" -InstallDirRegKey HKLM "Software\XBT\Tracker" "InstallDir" -XPStyle on -Page directory -Page instfiles -UninstPage uninstConfirm -UninstPage instfiles - -Section "Install" - SetShellVarContext all - SetOutPath "$INSTDIR" - - Delete "$INSTDIR\XBT Tracker.exe" - Delete "$INSTDIR\XBT Tracker Old.exe" - Rename "$INSTDIR\XBT Tracker.exe" "$INSTDIR\XBT Tracker Old.exe" - File "release\XBT Tracker.exe" - File xbt_tracker.conf.default - File xbt_tracker.sql - SetOverwrite off - File /oname=xbt_tracker.conf xbt_tracker.conf.default - SetOutPath "$INSTDIR\htdocs" - File htdocs\* - Exec "$INSTDIR\XBT Tracker.exe --install" - WriteUninstaller "$INSTDIR\Uninstall.exe" - CreateShortCut "$SMPROGRAMS\XBT Tracker.lnk" "$INSTDIR\XBT Tracker.exe" - WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\XBT Tracker" "DisplayName" "XBT Tracker ${VERSION}" - WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\XBT Tracker" "UninstallString" '"$INSTDIR\Uninstall.exe"' - WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\XBT Tracker" "NoModify" 1 - WriteRegStr HKLM "Software\XBT\Tracker" "InstallDir" "$INSTDIR" -SectionEnd - -Section "Uninstall" - SetShellVarContext all - ExecWait 'net stop "XBT Tracker"' - ExecWait "$INSTDIR\XBT Tracker.exe --uninstall" - Delete "$SMPROGRAMS\XBT Tracker.lnk" - DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\XBT Tracker" - DeleteRegKey HKLM "Software\XBT\Tracker" - DeleteRegKey /ifempty HKLM "Software\XBT" - RMDir /r "$PROGRAMFILES\XBT\Tracker" - RMDir "$PROGRAMFILES\XBT" -SectionEnd diff --git a/install/xbt/linux/Tracker/XBT Tracker.rc b/install/xbt/linux/Tracker/XBT Tracker.rc deleted file mode 100644 index c7dafe654..000000000 --- a/install/xbt/linux/Tracker/XBT Tracker.rc +++ /dev/null @@ -1,3 +0,0 @@ -#include "resource.h" - -IDR_MAINFRAME ICON "res\\XBT Tracker.ico" diff --git a/install/xbt/linux/Tracker/XBT Tracker.sln b/install/xbt/linux/Tracker/XBT Tracker.sln deleted file mode 100644 index 59cf16a96..000000000 --- a/install/xbt/linux/Tracker/XBT Tracker.sln +++ /dev/null @@ -1,20 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "XBT Tracker", "XBT Tracker.vcproj", "{73C570AC-E7C3-451D-A5C6-7A2532F0121B}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Win32 = Debug|Win32 - Release|Win32 = Release|Win32 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {73C570AC-E7C3-451D-A5C6-7A2532F0121B}.Debug|Win32.ActiveCfg = Debug|Win32 - {73C570AC-E7C3-451D-A5C6-7A2532F0121B}.Debug|Win32.Build.0 = Debug|Win32 - {73C570AC-E7C3-451D-A5C6-7A2532F0121B}.Release|Win32.ActiveCfg = Release|Win32 - {73C570AC-E7C3-451D-A5C6-7A2532F0121B}.Release|Win32.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/install/xbt/linux/Tracker/XBT Tracker.vcproj b/install/xbt/linux/Tracker/XBT Tracker.vcproj deleted file mode 100644 index 9e4b290e2..000000000 --- a/install/xbt/linux/Tracker/XBT Tracker.vcproj +++ /dev/null @@ -1,709 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/install/xbt/linux/Tracker/XBT Tracker.vcxproj b/install/xbt/linux/Tracker/XBT Tracker.vcxproj deleted file mode 100644 index 5e56f4abd..000000000 --- a/install/xbt/linux/Tracker/XBT Tracker.vcxproj +++ /dev/null @@ -1,265 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {73C570AC-E7C3-451D-A5C6-7A2532F0121B} - XBT Tracker - - - - Application - false - MultiByte - - - Application - false - MultiByte - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30319.1 - $(SolutionDir)$(Configuration)\ - $(Configuration)\ - false - $(SolutionDir)$(Configuration)\ - $(Configuration)\ - true - - - - - - - - MaxSpeed - OnlyExplicitInline - true - ..\misc;%(AdditionalIncludeDirectories) - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - MultiThreaded - true - Use - stdafx.h - Level3 - - - NDEBUG;%(PreprocessorDefinitions) - 0x0413 - - - zlib.lib;%(AdditionalDependencies) - Console - UseLinkTimeCodeGeneration - false - - - MachineX86 - - - - - - - - - Disabled - ..\misc;%(AdditionalIncludeDirectories) - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - Use - stdafx.h - Level1 - EditAndContinue - - - _DEBUG;%(PreprocessorDefinitions) - 0x0413 - - - zlib.lib;%(AdditionalDependencies) - libcmt;%(IgnoreSpecificDefaultLibraries) - true - Console - false - - - MachineX86 - - - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Create - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - Create - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - %(AdditionalIncludeDirectories) - %(PreprocessorDefinitions) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/install/xbt/linux/Tracker/client.h b/install/xbt/linux/Tracker/client.h deleted file mode 100644 index 3f6f9eadf..000000000 --- a/install/xbt/linux/Tracker/client.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include - -class Cserver; - -class Cclient -{ -public: - virtual void process_events(int) = 0; - virtual ~Cclient() - { - } -protected: - const Csocket& s() const - { - return m_s; - } - - void s(const Csocket& s) - { - m_s = s; - } - - Csocket m_s; - Cserver* m_server; -}; diff --git a/install/xbt/linux/Tracker/config.cpp b/install/xbt/linux/Tracker/config.cpp deleted file mode 100644 index 0f19cf731..000000000 --- a/install/xbt/linux/Tracker/config.cpp +++ /dev/null @@ -1,146 +0,0 @@ -#include "stdafx.h" -#include "config.h" - -#include -#include - -Cconfig::Cconfig() -{ - fill_maps(NULL); -} - -Cconfig::Cconfig(const Cconfig& v) -{ - fill_maps(&v); -} - -const Cconfig& Cconfig::operator=(const Cconfig& v) -{ - fill_maps(&v); - return *this; -} - -void Cconfig::fill_maps(const Cconfig* v) -{ - { - t_attribute attributes[] = - { - "auto_register", &m_auto_register, false, - "anonymous_connect", &m_anonymous_connect, true, - "anonymous_announce", &m_anonymous_announce, true, - "anonymous_scrape", &m_anonymous_scrape, true, - "daemon", &m_daemon, true, - "debug", &m_debug, false, - "full_scrape", &m_full_scrape, false, - "gzip_debug", &m_gzip_debug, true, - "gzip_scrape", &m_gzip_scrape, true, - "log_access", &m_log_access, false, - "log_announce", &m_log_announce, false, - "log_scrape", &m_log_scrape, false, - - // TorrentPier begin - "gdc", &m_gdc, true, - "free_leech", &m_free_leech, false, - "trust_ipv6", &m_trust_ipv6, false, - // TorrentPier end - - NULL - }; - fill_map(attributes, v ? &v->m_attributes_bool : NULL, m_attributes_bool); - } - { - t_attribute attributes[] = - { - "announce_interval", &m_announce_interval, 1800, - "clean_up_interval", &m_clean_up_interval, 60, - "read_config_interval", &m_read_config_interval, 60, - "read_db_interval", &m_read_db_interval, 60, - "scrape_interval", &m_scrape_interval, 0, - "write_db_interval", &m_write_db_interval, 15, - - // TorrentPier begin - "cheat_upload", &m_cheat_upload, 18, - "read_files_interval", &m_read_files_interval, 60, - // TorrentPier end - - NULL - }; - fill_map(attributes, v ? &v->m_attributes_int : NULL, m_attributes_int); - } - { - t_attribute attributes[] = - { - "column_files_completed", &m_column_files_completed, "completed", - "column_files_fid", &m_column_files_fid, "fid", - "column_files_leechers", &m_column_files_leechers, "leechers", - "column_files_seeders", &m_column_files_seeders, "seeders", - "column_users_uid", &m_column_users_uid, "uid", - "mysql_database", &m_mysql_database, "xbt", - "mysql_host", &m_mysql_host, "localhost", - "mysql_password", &m_mysql_password, "", - "mysql_table_prefix", &m_mysql_table_prefix, "xbt_", - "mysql_user", &m_mysql_user, "", - "offline_message", &m_offline_message, "", - "pid_file", &m_pid_file, "", - "query_log", &m_query_log, "", - "redirect_url", &m_redirect_url, "", - "table_announce_log", &m_table_announce_log, "", - "table_deny_from_hosts", &m_table_deny_from_hosts, "", - "table_files", &m_table_files, "", - "table_files_users", &m_table_files_users, "", - "table_scrape_log", &m_table_scrape_log, "", - "table_users", &m_table_users, "", - "torrent_pass_private_key", &m_torrent_pass_private_key, "", - - // TorrentPier begin - "column_files_dl_percent", &m_column_files_dl_percent, "", - "column_users_can_leech", &m_column_users_can_leech, "", - "column_users_torrents_limit", &m_column_users_torrents_limit, "", - // TorrentPier end - - NULL, NULL, "" - }; - fill_map(attributes, v ? &v->m_attributes_string : NULL, m_attributes_string); - } - if (v) - { - m_listen_ipas = v->m_listen_ipas; - m_listen_ports = v->m_listen_ports; - } -} - -int Cconfig::set(const std::string& name, const std::string& value) -{ - if (t_attribute* i = find_ptr(m_attributes_string, name)) - *i->value = value; - else if (name == "listen_ipa") - - // TorrentPier begin - m_listen_ipas.insert(value); - else if (name == "listen_port") - m_listen_ports.insert(value); - // TorrentPier end - - else - return set(name, atoi(value.c_str())); - return 0; -} - -int Cconfig::set(const std::string& name, int value) -{ - if (t_attribute* i = find_ptr(m_attributes_int, name)) - *i->value = value; - // TorrentPier // listen_port - else - return set(name, static_cast(value)); - return 0; -} - -int Cconfig::set(const std::string& name, bool value) -{ - if (t_attribute* i = find_ptr(m_attributes_bool, name)) - *i->value = value; - else - return 1; - return 0; -} diff --git a/install/xbt/linux/Tracker/config.h b/install/xbt/linux/Tracker/config.h deleted file mode 100644 index 0a309c305..000000000 --- a/install/xbt/linux/Tracker/config.h +++ /dev/null @@ -1,75 +0,0 @@ -#pragma once - -#include - -class Cconfig: public Cconfig_base -{ -public: - // TorrentPier begin - typedef std::set t_listen_ipas; - typedef std::set t_listen_ports; - // TorrentPier end - - int set(const std::string& name, const std::string& value); - int set(const std::string& name, int value); - int set(const std::string& name, bool value); - Cconfig(); - Cconfig(const Cconfig&); - const Cconfig& operator=(const Cconfig&); - - bool m_anonymous_announce; - bool m_anonymous_connect; - bool m_anonymous_scrape; - bool m_auto_register; - bool m_daemon; - bool m_debug; - bool m_full_scrape; - bool m_gzip_debug; - bool m_gzip_scrape; - bool m_log_access; - bool m_log_announce; - bool m_log_scrape; - int m_announce_interval; - int m_clean_up_interval; - int m_read_config_interval; - int m_read_db_interval; - int m_scrape_interval; - int m_write_db_interval; - std::string m_column_files_completed; - std::string m_column_files_fid; - std::string m_column_files_leechers; - std::string m_column_files_seeders; - std::string m_column_users_uid; - std::string m_mysql_database; - std::string m_mysql_host; - std::string m_mysql_password; - std::string m_mysql_table_prefix; - std::string m_mysql_user; - std::string m_offline_message; - std::string m_query_log; - std::string m_pid_file; - std::string m_redirect_url; - std::string m_table_announce_log; - std::string m_table_deny_from_hosts; - std::string m_table_files; - std::string m_table_files_users; - std::string m_table_scrape_log; - std::string m_table_users; - std::string m_torrent_pass_private_key; - t_listen_ipas m_listen_ipas; - t_listen_ports m_listen_ports; - - // TorrentPier begin - bool m_gdc; - bool m_free_leech; - std::string m_column_files_dl_percent; - std::string m_column_users_can_leech; - std::string m_column_users_torrents_limit; - int m_read_files_interval; - bool m_trust_ipv6; - int m_cheat_upload; - // TorrentPier end - -private: - void fill_maps(const Cconfig*); -}; diff --git a/install/xbt/linux/Tracker/connection.cpp b/install/xbt/linux/Tracker/connection.cpp deleted file mode 100644 index 71a78b8de..000000000 --- a/install/xbt/linux/Tracker/connection.cpp +++ /dev/null @@ -1,340 +0,0 @@ -#include "stdafx.h" -#include "connection.h" - -#include -#include -#include -#include -#include -#include "server.h" - -// TorrentPier begin - -#ifdef WIN32 -#include -#endif - -#define PASS_SIZE1 10 -#define PASS_SIZE2 32 - -Cconnection::Cconnection(Cserver* server, const Csocket& s, const sockaddr_storage& a) -// TorrentPier end -{ - m_server = server; - m_s = s; - m_a = a; - m_ctime = server->time(); - - m_state = 0; - m_r.clear(); - m_w = m_read_b; -} - -int Cconnection::pre_select(fd_set* fd_read_set, fd_set* fd_write_set) -{ - FD_SET(m_s, fd_read_set); - if (!m_r.empty()) - FD_SET(m_s, fd_write_set); - return m_s; -} - -int Cconnection::post_select(fd_set* fd_read_set, fd_set* fd_write_set) -{ - return FD_ISSET(m_s, fd_read_set) && recv() - || FD_ISSET(m_s, fd_write_set) && send() - || m_server->time() - m_ctime > 10 - || m_state == 5 && m_r.empty(); -} - -int Cconnection::recv() -{ - int r = m_s.recv(m_w); - if (!r) - { - m_state = 5; - return 0; - } - if (r == SOCKET_ERROR) - { - int e = WSAGetLastError(); - switch (e) - { - case WSAECONNABORTED: - case WSAECONNRESET: - return 1; - case WSAEWOULDBLOCK: - return 0; - } - std::cerr << "recv failed: " << Csocket::error2a(e) << std::endl; - return 1; - } - if (m_state == 5) - return 0; - const unsigned char* a = m_w; - m_w += r; - int state; - do - { - state = m_state; - while (a < m_w && *a != '\n' && *a != '\r') - { - a++; - if (m_state) - m_state = 1; - } - if (a < m_w) - { - switch (m_state) - { - case 0: - read(std::string(&m_read_b.front(), reinterpret_cast(a) - &m_read_b.front())); - m_state = 1; - case 1: - case 3: - m_state += *a == '\n' ? 2 : 1; - break; - case 2: - case 4: - m_state++; - break; - } - a++; - } - } - while (state != m_state); - return 0; -} - -int Cconnection::send() -{ - if (m_r.empty()) - return 0; - int r = m_s.send(m_r); - if (r == SOCKET_ERROR) - { - int e = WSAGetLastError(); - switch (e) - { - case WSAECONNABORTED: - case WSAECONNRESET: - return 1; - case WSAEWOULDBLOCK: - return 0; - } - std::cerr << "send failed: " << Csocket::error2a(e) << std::endl; - return 1; - } - m_r += r; - if (m_r.empty()) - m_write_b.clear(); - return 0; -} - -void Cconnection::read(const std::string& v) -{ -#ifndef NDEBUG - std::cout << v << std::endl; -#endif - if (m_server->config().m_log_access) - { - // TorrentPier begin - char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV]; - if (!getnameinfo(reinterpret_cast(&m_a), sizeof(m_a), hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV)) { - static std::ofstream f("xbt_tracker_raw.log"); - f << m_server->time() << '\t' << hbuf << '\t' << sbuf << '\t' << v << std::endl; - } - } - Ctracker_input ti(m_a.ss_family); - // TorrentPier end - - size_t e = v.find('?'); - if (e == std::string::npos) - e = v.size(); - else - { - size_t a = e + 1; - size_t b = v.find(' ', a); - if (b == std::string::npos) - return; - while (a < b) - { - // TorrentPier begin - if( v[a] == '&' || v[a] == '?' ) { a++; continue; } // "&&?" hack - // TorrentPier end - - size_t c = v.find('=', a); - if (c++ == std::string::npos) - break; - size_t d = v.find_first_of(" &", c); - if (d == std::string::npos) - break; - ti.set(v.substr(a, c - a - 1), uri_decode(v.substr(c, d - c))); - a = d + 1; - } - } - - // TorrentPier begin - if (m_a.ss_family == AF_INET) { - sockaddr_in *b = reinterpret_cast(&m_a); - if (!ti.m_ipa || !is_private_ipa(b->sin_addr.s_addr)) - ti.m_ipa = b->sin_addr.s_addr; - } else if (m_a.ss_family == AF_INET6) { - sockaddr_in6 *b = reinterpret_cast(&m_a); - ti.m_ipv6set = true; - memcpy(ti.m_ipv6bin, &(b->sin6_addr), 16); - } - - std::string torrent_pass0 = ti.m_passkey; - // TorrentPier end - - size_t a = 4; - if (a < e && v[a] == '/') - { - do { a++; - } while (a < e && v[a] == '/'); - - if (a + 1 < e && v[a + 1] == '/') - a += 2; - - // TorrentPier begin - if (a + 2 < e && v[a + 2] == '/') // Skip "/bt/" - a += 3; - - if (a + PASS_SIZE1 < e && v[a + PASS_SIZE1] == '/') - { - torrent_pass0 = v.substr(a, PASS_SIZE1); - a += PASS_SIZE1+1; - } - - if (a + PASS_SIZE2 < e && v[a + PASS_SIZE2] == '/') - { - torrent_pass0 = v.substr(a, PASS_SIZE2); - a += PASS_SIZE2+1; - } - // TorrentPier end - } - std::string h = "HTTP/1.0 200 OK\r\n"; - Cvirtual_binary s; - bool gzip = true; - switch (a < v.size() ? v[a] : 0) - { - case 'a': - if (!ti.valid()) - break; - gzip = false; - if (ti.banned()) - s = Cbvalue().d(bts_failure_reason, bts_banned_client).read(); - else if (0) - s = Cbvalue().d(bts_failure_reason, bts_banned_client).read(); - else - { - std::string error = m_server->insert_peer(ti, false, m_server->find_user_by_torrent_pass(torrent_pass0, ti.m_info_hash)); - s = error.empty() ? m_server->select_peers(ti) : Cbvalue().d(bts_failure_reason, error).read(); - } - break; - case 'd': - if (m_server->config().m_debug) - { - gzip = m_server->config().m_gzip_debug; - h += "Content-Type: text/html; charset=us-ascii\r\n"; - s = Cvirtual_binary(m_server->debug(ti)); - } - break; - case 's': - if (v.size() >= 7 && v[6] == 't') - { - gzip = m_server->config().m_gzip_debug; - h += "Content-Type: text/html; charset=us-ascii\r\n"; - s = Cvirtual_binary(m_server->statistics()); - } - else if (m_server->config().m_full_scrape || ti.m_compact || !ti.m_info_hash.empty()) - { - gzip = m_server->config().m_gzip_scrape && !ti.m_compact && ti.m_info_hash.empty(); - s = m_server->scrape(ti); - } - break; - } - if (s.empty()) - { - if (!ti.m_peer_id.empty() || m_server->config().m_redirect_url.empty()) - h = "HTTP/1.0 404 Not Found\r\n"; - else - { - h = "HTTP/1.0 302 Found\r\n" - "Location: " + m_server->config().m_redirect_url + (ti.m_info_hash.empty() ? "" : "?info_hash=" + uri_encode(ti.m_info_hash)) + "\r\n"; - } - } - else if (gzip) - { - Cvirtual_binary s2 = xcc_z::gzip(s); -#ifndef NDEBUG - static std::ofstream f("xbt_tracker_gzip.log"); - f << m_server->time() << '\t' << v[5] << '\t' << s.size() << '\t' << s2.size() << std::endl; -#endif - if (s2.size() + 24 < s.size()) - { - h += "Content-Encoding: gzip\r\n"; - s = s2; - } - } - h += "\r\n"; -#ifdef WIN32 - m_write_b.resize(h.size() + s.size()); - memcpy(m_write_b.data_edit(), h.data(), h.size()); - s.read(m_write_b.data_edit() + h.size()); - int r = m_s.send(m_write_b); -#else - boost::array d; - d[0].iov_base = const_cast(h.data()); - d[0].iov_len = h.size(); - d[1].iov_base = const_cast(s.data()); - d[1].iov_len = s.size(); - msghdr m; - m.msg_name = NULL; - m.msg_namelen = 0; - m.msg_iov = const_cast(d.data()); - m.msg_iovlen = d.size(); - m.msg_control = NULL; - m.msg_controllen = 0; - m.msg_flags = 0; - int r = sendmsg(m_s, &m, MSG_NOSIGNAL); -#endif - if (r == SOCKET_ERROR) - { - if (WSAGetLastError() != WSAECONNRESET) - std::cerr << "send failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; - } - else if (r != h.size() + s.size()) - { -#ifndef WIN32 - if (r < h.size()) - { - m_write_b.resize(h.size() + s.size()); - memcpy(m_write_b.data_edit(), h.data(), h.size()); - s.read(m_write_b.data_edit() + h.size()); - } - else - { - m_write_b = s; - r -= h.size(); - } -#endif - m_r = m_write_b; - m_r += r; - } - if (m_r.empty()) - m_write_b.clear(); -} - -void Cconnection::process_events(int events) -{ - if (events & (EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP) && recv() - || events & EPOLLOUT && send() - || m_state == 5 && m_write_b.empty()) - m_s.close(); -} - -int Cconnection::run() -{ - return s() == INVALID_SOCKET || m_server->time() - m_ctime > 10; -} diff --git a/install/xbt/linux/Tracker/connection.h b/install/xbt/linux/Tracker/connection.h deleted file mode 100644 index 9bdba027a..000000000 --- a/install/xbt/linux/Tracker/connection.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include "client.h" -#include -#include - -class Cserver; - -class Cconnection: public Cclient, boost::noncopyable -{ -public: - Cclient::s; - int run(); - void read(const std::string&); - int recv(); - int send(); - virtual void process_events(int); - int pre_select(fd_set* fd_read_set, fd_set* fd_write_set); - int post_select(fd_set* fd_read_set, fd_set* fd_write_set); - - // TorrentPier begin - Cconnection(Cserver*, const Csocket&, const sockaddr_storage&); -private: - sockaddr_storage m_a; - // TorrentPier end - - time_t m_ctime; - int m_state; - boost::array m_read_b; - Cvirtual_binary m_write_b; - const_memory_range m_r; - memory_range m_w; -}; diff --git a/install/xbt/linux/Tracker/epoll.cpp b/install/xbt/linux/Tracker/epoll.cpp deleted file mode 100644 index cce7bed39..000000000 --- a/install/xbt/linux/Tracker/epoll.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "stdafx.h" -#include "epoll.h" - -Cepoll::Cepoll() -{ - m_fd = -1; -} - -Cepoll::~Cepoll() -{ -#ifdef EPOLL - if (m_fd != -1) - close(m_fd); -#endif -} - -int Cepoll::create(int size) -{ -#ifdef EPOLL - return m_fd = epoll_create(size); -#else - return 0; -#endif -} - -int Cepoll::ctl(int op, int fd, int events, void* p) -{ -#ifdef EPOLL - epoll_event e; - e.data.ptr = p; - e.events = events; - return epoll_ctl(m_fd, op, fd, &e); -#else - return 0; -#endif -} - -int Cepoll::wait(epoll_event* events, int maxevents, int timeout) -{ -#ifdef EPOLL - return epoll_wait(m_fd, events, maxevents, timeout); -#else - return 0; -#endif -} diff --git a/install/xbt/linux/Tracker/epoll.h b/install/xbt/linux/Tracker/epoll.h deleted file mode 100644 index 6aa9b7198..000000000 --- a/install/xbt/linux/Tracker/epoll.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include - -#ifdef EPOLL -#include -#else -enum -{ - EPOLLIN = 1, - EPOLLOUT = 2, - EPOLLPRI = 4, - EPOLLERR = 8, - EPOLLHUP = 0x10, - EPOLLET = 0x20, - EPOLLONESHOT = 0x40, -}; - -enum -{ - EPOLL_CTL_ADD = 1, - EPOLL_CTL_MOD = 2, - EPOLL_CTL_DEL = 4, -}; - -typedef void epoll_event; -#endif - -class Cepoll: boost::noncopyable -{ -public: - int create(int size); - int ctl(int op, int fd, int events, void* p); - int wait(epoll_event* events, int maxevents, int timeout); - Cepoll(); - ~Cepoll(); -private: - int m_fd; -}; diff --git a/install/xbt/linux/Tracker/make.bsd.google_perftools.sh b/install/xbt/linux/Tracker/make.bsd.google_perftools.sh deleted file mode 100644 index f69d1bdce..000000000 --- a/install/xbt/linux/Tracker/make.bsd.google_perftools.sh +++ /dev/null @@ -1 +0,0 @@ -g++ $@ -DNDEBUG -DPEERS_KEY -ltcmalloc -I /usr/local/include -I ../misc -I . -O3 -o xbt_tracker *.cpp ../misc/*.cpp ../misc/sql/*.cpp `mysql_config --libs` && strip xbt_tracker diff --git a/install/xbt/linux/Tracker/make.bsd.sh b/install/xbt/linux/Tracker/make.bsd.sh deleted file mode 100644 index 581aa1b9c..000000000 --- a/install/xbt/linux/Tracker/make.bsd.sh +++ /dev/null @@ -1 +0,0 @@ -g++ $@ -DNDEBUG -DPEERS_KEY -I /usr/local/include -I ../misc -I . -O3 -o xbt_tracker *.cpp ../misc/*.cpp ../misc/sql/*.cpp `mysql_config --libs` && strip xbt_tracker diff --git a/install/xbt/linux/Tracker/make.sh b/install/xbt/linux/Tracker/make.sh deleted file mode 100644 index f536e4552..000000000 --- a/install/xbt/linux/Tracker/make.sh +++ /dev/null @@ -1,20 +0,0 @@ -g++ $@ -DNDEBUG -I ../misc -I . -O3 -o xbt_tracker \ - ../misc/sql/database.cpp \ - ../misc/sql/sql_query.cpp \ - ../misc/sql/sql_result.cpp \ - ../misc/bt_misc.cpp \ - ../misc/bvalue.cpp \ - ../misc/sha1.cpp \ - ../misc/socket.cpp \ - ../misc/virtual_binary.cpp \ - ../misc/xcc_z.cpp \ - config.cpp \ - connection.cpp \ - epoll.cpp \ - server.cpp \ - tcp_listen_socket.cpp \ - tracker_input.cpp \ - transaction.cpp \ - udp_listen_socket.cpp \ - "XBT Tracker.cpp" \ - `mysql_config --libs` && strip xbt_tracker diff --git a/install/xbt/linux/Tracker/md5.cpp b/install/xbt/linux/Tracker/md5.cpp deleted file mode 100644 index 7c215789c..000000000 --- a/install/xbt/linux/Tracker/md5.cpp +++ /dev/null @@ -1,362 +0,0 @@ -/* MD5 - converted to C++ class by Frank Thilo (thilo@unix-ag.org) - for bzflag (http://www.bzflag.org) - - based on: - - md5.h and md5.c - reference implemantion of RFC 1321 - - Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All -rights reserved. - -License to copy and use this software is granted provided that it -is identified as the "RSA Data Security, Inc. MD5 Message-Digest -Algorithm" in all material mentioning or referencing this software -or this function. - -License is also granted to make and use derivative works provided -that such works are identified as "derived from the RSA Data -Security, Inc. MD5 Message-Digest Algorithm" in all material -mentioning or referencing the derived work. - -RSA Data Security, Inc. makes no representations concerning either -the merchantability of this software or the suitability of this -software for any particular purpose. It is provided "as is" -without express or implied warranty of any kind. - -These notices must be retained in any copies of any part of this -documentation and/or software. - -*/ - -/* interface header */ -#include "md5.h" - -/* system implementation headers */ -#include -#include - -// Constants for MD5Transform routine. -#define S11 7 -#define S12 12 -#define S13 17 -#define S14 22 -#define S21 5 -#define S22 9 -#define S23 14 -#define S24 20 -#define S31 4 -#define S32 11 -#define S33 16 -#define S34 23 -#define S41 6 -#define S42 10 -#define S43 15 -#define S44 21 - -/////////////////////////////////////////////// - -// F, G, H and I are basic MD5 functions. -inline MD5::uint4 MD5::F(uint4 x, uint4 y, uint4 z) { - return x&y | ~x&z; -} - -inline MD5::uint4 MD5::G(uint4 x, uint4 y, uint4 z) { - return x&z | y&~z; -} - -inline MD5::uint4 MD5::H(uint4 x, uint4 y, uint4 z) { - return x^y^z; -} - -inline MD5::uint4 MD5::I(uint4 x, uint4 y, uint4 z) { - return y ^ (x | ~z); -} - -// rotate_left rotates x left n bits. -inline MD5::uint4 MD5::rotate_left(uint4 x, int n) { - return (x << n) | (x >> (32-n)); -} - -// FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. -// Rotation is separate from addition to prevent recomputation. -inline void MD5::FF(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac) { - a = rotate_left(a+ F(b,c,d) + x + ac, s) + b; -} - -inline void MD5::GG(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac) { - a = rotate_left(a + G(b,c,d) + x + ac, s) + b; -} - -inline void MD5::HH(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac) { - a = rotate_left(a + H(b,c,d) + x + ac, s) + b; -} - -inline void MD5::II(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac) { - a = rotate_left(a + I(b,c,d) + x + ac, s) + b; -} - -////////////////////////////////////////////// - -// default ctor, just initailize -MD5::MD5() -{ - init(); -} - -////////////////////////////////////////////// - -// nifty shortcut ctor, compute MD5 for string and finalize it right away -MD5::MD5(const std::string &text) -{ - init(); - update(text.c_str(), text.length()); - finalize(); -} - -////////////////////////////// - -void MD5::init() -{ - finalized=false; - - count[0] = 0; - count[1] = 0; - - // load magic initialization constants. - state[0] = 0x67452301; - state[1] = 0xefcdab89; - state[2] = 0x98badcfe; - state[3] = 0x10325476; -} - -////////////////////////////// - -// decodes input (unsigned char) into output (uint4). Assumes len is a multiple of 4. -void MD5::decode(uint4 output[], const uint1 input[], size_type len) -{ - for (unsigned int i = 0, j = 0; j < len; i++, j += 4) - output[i] = ((uint4)input[j]) | (((uint4)input[j+1]) << 8) | - (((uint4)input[j+2]) << 16) | (((uint4)input[j+3]) << 24); -} - -////////////////////////////// - -// encodes input (uint4) into output (unsigned char). Assumes len is -// a multiple of 4. -void MD5::encode(uint1 output[], const uint4 input[], size_type len) -{ - for (size_type i = 0, j = 0; j < len; i++, j += 4) { - output[j] = input[i] & 0xff; - output[j+1] = (input[i] >> 8) & 0xff; - output[j+2] = (input[i] >> 16) & 0xff; - output[j+3] = (input[i] >> 24) & 0xff; - } -} - -////////////////////////////// - -// apply MD5 algo on a block -void MD5::transform(const uint1 block[blocksize]) -{ - uint4 a = state[0], b = state[1], c = state[2], d = state[3], x[16]; - decode (x, block, blocksize); - - /* Round 1 */ - FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */ - FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */ - FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */ - FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */ - FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */ - FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */ - FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */ - FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */ - FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */ - FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */ - FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */ - FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */ - FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */ - FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */ - FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */ - FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */ - - /* Round 2 */ - GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */ - GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */ - GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */ - GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */ - GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */ - GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */ - GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */ - GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */ - GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */ - GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */ - GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */ - GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */ - GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */ - GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */ - GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */ - GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */ - - /* Round 3 */ - HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */ - HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */ - HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */ - HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */ - HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */ - HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */ - HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */ - HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */ - HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */ - HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */ - HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */ - HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */ - HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */ - HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */ - HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */ - HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */ - - /* Round 4 */ - II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */ - II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */ - II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */ - II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */ - II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */ - II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */ - II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */ - II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */ - II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */ - II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */ - II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */ - II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */ - II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */ - II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */ - II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */ - II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */ - - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; - - // Zeroize sensitive information. - memset(x, 0, sizeof x); -} - -////////////////////////////// - -// MD5 block update operation. Continues an MD5 message-digest -// operation, processing another message block -void MD5::update(const unsigned char input[], size_type length) -{ - // compute number of bytes mod 64 - size_type index = count[0] / 8 % blocksize; - - // Update number of bits - if ((count[0] += (length << 3)) < (length << 3)) - count[1]++; - count[1] += (length >> 29); - - // number of bytes we need to fill in buffer - size_type firstpart = 64 - index; - - size_type i; - - // transform as many times as possible. - if (length >= firstpart) - { - // fill buffer first, transform - memcpy(&buffer[index], input, firstpart); - transform(buffer); - - // transform chunks of blocksize (64 bytes) - for (i = firstpart; i + blocksize <= length; i += blocksize) - transform(&input[i]); - - index = 0; - } - else - i = 0; - - // buffer remaining input - memcpy(&buffer[index], &input[i], length-i); -} - -////////////////////////////// - -// for convenience provide a verson with signed char -void MD5::update(const char input[], size_type length) -{ - update((const unsigned char*)input, length); -} - -////////////////////////////// - -// MD5 finalization. Ends an MD5 message-digest operation, writing the -// the message digest and zeroizing the context. -MD5& MD5::finalize() -{ - static unsigned char padding[64] = { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - - if (!finalized) { - // Save number of bits - unsigned char bits[8]; - encode(bits, count, 8); - - // pad out to 56 mod 64. - size_type index = count[0] / 8 % 64; - size_type padLen = (index < 56) ? (56 - index) : (120 - index); - update(padding, padLen); - - // Append length (before padding) - update(bits, 8); - - // Store state in digest - encode(digest, state, 16); - - // Zeroize sensitive information. - memset(buffer, 0, sizeof buffer); - memset(count, 0, sizeof count); - - finalized=true; - } - - return *this; -} - -////////////////////////////// - -// return hex representation of digest as string -std::string MD5::hexdigest() const -{ - if (!finalized) - return ""; - - char buf[33]; - for (int i=0; i<16; i++) - sprintf(buf+i*2, "%02x", digest[i]); - buf[32]=0; - - return std::string(buf); -} - -////////////////////////////// - -std::ostream& operator<<(std::ostream& out, MD5 md5) -{ - return out << md5.hexdigest(); -} - -////////////////////////////// - -std::string md5(const std::string str) -{ - MD5 md5 = MD5(str); - - return md5.hexdigest(); -} diff --git a/install/xbt/linux/Tracker/md5.h b/install/xbt/linux/Tracker/md5.h deleted file mode 100644 index 4f6a8cebd..000000000 --- a/install/xbt/linux/Tracker/md5.h +++ /dev/null @@ -1,93 +0,0 @@ -/* MD5 - converted to C++ class by Frank Thilo (thilo@unix-ag.org) - for bzflag (http://www.bzflag.org) - - based on: - - md5.h and md5.c - reference implementation of RFC 1321 - - Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All -rights reserved. - -License to copy and use this software is granted provided that it -is identified as the "RSA Data Security, Inc. MD5 Message-Digest -Algorithm" in all material mentioning or referencing this software -or this function. - -License is also granted to make and use derivative works provided -that such works are identified as "derived from the RSA Data -Security, Inc. MD5 Message-Digest Algorithm" in all material -mentioning or referencing the derived work. - -RSA Data Security, Inc. makes no representations concerning either -the merchantability of this software or the suitability of this -software for any particular purpose. It is provided "as is" -without express or implied warranty of any kind. - -These notices must be retained in any copies of any part of this -documentation and/or software. - -*/ - -#ifndef BZF_MD5_H -#define BZF_MD5_H - -#include -#include - - -// a small class for calculating MD5 hashes of strings or byte arrays -// it is not meant to be fast or secure -// -// usage: 1) feed it blocks of uchars with update() -// 2) finalize() -// 3) get hexdigest() string -// or -// MD5(std::string).hexdigest() -// -// assumes that char is 8 bit and int is 32 bit -class MD5 -{ -public: - typedef unsigned int size_type; // must be 32bit - - MD5(); - MD5(const std::string& text); - void update(const unsigned char *buf, size_type length); - void update(const char *buf, size_type length); - MD5& finalize(); - std::string hexdigest() const; - friend std::ostream& operator<<(std::ostream&, MD5 md5); - -private: - void init(); - typedef unsigned char uint1; // 8bit - typedef unsigned int uint4; // 32bit - enum {blocksize = 64}; // VC6 won't eat a const static int here - - void transform(const uint1 block[blocksize]); - static void decode(uint4 output[], const uint1 input[], size_type len); - static void encode(uint1 output[], const uint4 input[], size_type len); - - bool finalized; - uint1 buffer[blocksize]; // bytes that didn't fit in last 64 byte chunk - uint4 count[2]; // 64bit counter for number of bits (lo, hi) - uint4 state[4]; // digest so far - uint1 digest[16]; // the result - - // low level logic operations - static inline uint4 F(uint4 x, uint4 y, uint4 z); - static inline uint4 G(uint4 x, uint4 y, uint4 z); - static inline uint4 H(uint4 x, uint4 y, uint4 z); - static inline uint4 I(uint4 x, uint4 y, uint4 z); - static inline uint4 rotate_left(uint4 x, int n); - static inline void FF(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac); - static inline void GG(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac); - static inline void HH(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac); - static inline void II(uint4 &a, uint4 b, uint4 c, uint4 d, uint4 x, uint4 s, uint4 ac); -}; - -std::string md5(const std::string str); - -#endif diff --git a/install/xbt/linux/Tracker/res/XBT Tracker.ico b/install/xbt/linux/Tracker/res/XBT Tracker.ico deleted file mode 100644 index 0e2f5d148..000000000 Binary files a/install/xbt/linux/Tracker/res/XBT Tracker.ico and /dev/null differ diff --git a/install/xbt/linux/Tracker/resource.h b/install/xbt/linux/Tracker/resource.h deleted file mode 100644 index a810dc456..000000000 --- a/install/xbt/linux/Tracker/resource.h +++ /dev/null @@ -1,16 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Developer Studio generated include file. -// Used by XBT Client.rc -// -#define IDR_MAINFRAME 128 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NEXT_RESOURCE_VALUE 149 -#define _APS_NEXT_COMMAND_VALUE 32849 -#define _APS_NEXT_CONTROL_VALUE 1091 -#define _APS_NEXT_SYMED_VALUE 105 -#endif -#endif diff --git a/install/xbt/linux/Tracker/server.cpp b/install/xbt/linux/Tracker/server.cpp deleted file mode 100644 index 5739894a7..000000000 --- a/install/xbt/linux/Tracker/server.cpp +++ /dev/null @@ -1,1510 +0,0 @@ -#include "stdafx.h" -#include "server.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "transaction.h" - -// TorrentPier begin -#include "md5.cpp" -#ifdef WIN32 -#include -#endif - -long long gcd(long long a, long long b) { - long long c = 0; - while (b) { - c = a % b; - a = b; - b = c; - } - return a; -} -// TorrentPier end - -static volatile bool g_sig_term = false; - -Cserver::Cserver(Cdatabase& database, const std::string& table_prefix, bool use_sql, const std::string& conf_file): - m_database(database) -{ - m_fid_end = 0; - - for (int i = 0; i < 8; i++) - m_secret = m_secret << 8 ^ rand(); - m_conf_file = conf_file; - m_table_prefix = table_prefix; - m_time = ::time(NULL); - m_use_sql = use_sql; -} - -int Cserver::run() -{ - read_config(); - if (test_sql()) - return 1; - if (m_epoll.create(1 << 10) == -1) - { - std::cerr << "epoll_create failed" << std::endl; - return 1; - } - t_tcp_sockets lt; - t_udp_sockets lu; - - // TorrentPier begin - struct addrinfo hints, *res, *res0; - char hbuf[NI_MAXHOST], sbuf[NI_MAXSERV]; - memset(&hints, 0, sizeof(hints)); - hints.ai_socktype = SOCK_STREAM; - hints.ai_flags = AI_PASSIVE; - Csocket::start_up(); - - BOOST_FOREACH(Cconfig::t_listen_ipas::const_reference j, m_config.m_listen_ipas) - { - BOOST_FOREACH(Cconfig::t_listen_ports::const_reference i, m_config.m_listen_ports) - { - if (getaddrinfo(j == "*" ? NULL : j.c_str(), i.c_str(), &hints, &res0)) { - std::cerr << "getaddrinfo failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; - return 1; - } - for (res = res0; res; res = res->ai_next) { - int s = ::socket(res->ai_family, res->ai_socktype, res->ai_protocol); - if (s < 0) { - std::cerr << "socket failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; - return 1; - } - Csocket l(s); -#ifdef IPV6_V6ONLY - if (res->ai_family == AF_INET6 && - l.setsockopt(IPPROTO_IPV6, IPV6_V6ONLY, true)) { - std::cerr << "IPV6_V6ONLY failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; - } -#endif - if (l.blocking(false)) - std::cerr << "blocking failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; - else if (l.setsockopt(SOL_SOCKET, SO_REUSEADDR, true), - ::bind(s, res->ai_addr, res->ai_addrlen)) - std::cerr << "bind failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; - else if (::listen(s, INT_MAX)) - std::cerr << "listen failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; - else - { - if (getnameinfo(res->ai_addr, res->ai_addrlen, hbuf, sizeof(hbuf), sbuf, sizeof(sbuf), NI_NUMERICHOST | NI_NUMERICSERV)) - std::cerr << "getnameinfo failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; - else - std::cerr << "Listen to " << hbuf << " " << sbuf << std::endl; -#ifdef SO_ACCEPTFILTER - accept_filter_arg afa; - bzero(&afa, sizeof(afa)); - strcpy(afa.af_name, "httpready"); - if (l.setsockopt(SOL_SOCKET, SO_ACCEPTFILTER, &afa, sizeof(afa))) - std::cerr << "setsockopt failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; -#elif TCP_DEFER_ACCEPT - if (l.setsockopt(IPPROTO_TCP, TCP_DEFER_ACCEPT, true)) - std::cerr << "setsockopt failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; -#endif - lt.push_back(Ctcp_listen_socket(this, l)); - if (!m_epoll.ctl(EPOLL_CTL_ADD, l, EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLERR | EPOLLHUP, <.back())) - continue; - } - return 1; - } - } - - /* - BOOST_FOREACH(Cconfig::t_listen_ports::const_reference i, m_config.m_listen_ports) - { - Csocket l; - if (l.open(SOCK_DGRAM) == INVALID_SOCKET) - std::cerr << "socket failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; - else if (l.setsockopt(SOL_SOCKET, SO_REUSEADDR, true), - l.bind(j, htons(i))) - std::cerr << "bind failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; - else - { - lu.push_back(Cudp_listen_socket(this, l)); - if (!m_epoll.ctl(EPOLL_CTL_ADD, l, EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLHUP, &lu.back())) - continue; - } - return 1; - } - */ - } - // TorrentPier end - - clean_up(); - read_db_deny_from_hosts(); - read_db_files(); - read_db_users(); - write_db_files(); - write_db_users(); -#ifndef WIN32 - if (m_config.m_daemon) - { - if (daemon(true, false)) - std::cerr << "daemon failed" << std::endl; - std::ofstream(m_config.m_pid_file.c_str()) << getpid() << std::endl; - struct sigaction act; - act.sa_handler = sig_handler; - sigemptyset(&act.sa_mask); - act.sa_flags = 0; - if (sigaction(SIGTERM, &act, NULL)) - std::cerr << "sigaction failed" << std::endl; - act.sa_handler = SIG_IGN; - if (sigaction(SIGPIPE, &act, NULL)) - std::cerr << "sigaction failed" << std::endl; - } -#endif -#ifdef EPOLL - boost::array events; -#else - fd_set fd_read_set; - fd_set fd_write_set; - fd_set fd_except_set; -#endif - while (!g_sig_term) - { -#ifdef EPOLL - int r = m_epoll.wait(events.data(), events.size(), 5000); - if (r == -1) - std::cerr << "epoll_wait failed: " << errno << std::endl; - else - { - int prev_time = m_time; - m_time = ::time(NULL); - for (int i = 0; i < r; i++) - reinterpret_cast(events[i].data.ptr)->process_events(events[i].events); - if (m_time == prev_time) - continue; - for (t_connections::iterator i = m_connections.begin(); i != m_connections.end(); ) - { - if (i->run()) - i = m_connections.erase(i); - else - i++; - } - } -#else - FD_ZERO(&fd_read_set); - FD_ZERO(&fd_write_set); - FD_ZERO(&fd_except_set); - int n = 0; - BOOST_FOREACH(t_connections::reference i, m_connections) - { - int z = i.pre_select(&fd_read_set, &fd_write_set); - n = std::max(n, z); - } - BOOST_FOREACH(t_tcp_sockets::reference i, lt) - { - FD_SET(i.s(), &fd_read_set); - n = std::max(n, i.s()); - } - BOOST_FOREACH(t_udp_sockets::reference i, lu) - { - FD_SET(i.s(), &fd_read_set); - n = std::max(n, i.s()); - } - timeval tv; - tv.tv_sec = 5; - tv.tv_usec = 0; - if (select(n + 1, &fd_read_set, &fd_write_set, &fd_except_set, &tv) == SOCKET_ERROR) - std::cerr << "select failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; - else - { - m_time = ::time(NULL); - BOOST_FOREACH(t_tcp_sockets::reference i, lt) - { - if (FD_ISSET(i.s(), &fd_read_set)) - accept(i.s()); - } - BOOST_FOREACH(t_udp_sockets::reference i, lu) - { - if (FD_ISSET(i.s(), &fd_read_set)) - Ctransaction(*this, i.s()).recv(); - } - for (t_connections::iterator i = m_connections.begin(); i != m_connections.end(); ) - { - if (i->post_select(&fd_read_set, &fd_write_set)) - i = m_connections.erase(i); - else - i++; - } - } -#endif - if (time() - m_read_config_time > m_config.m_read_config_interval) - read_config(); - else if (time() - m_clean_up_time > m_config.m_clean_up_interval) - clean_up(); - else if (time() - m_read_db_deny_from_hosts_time > m_config.m_read_db_interval) - read_db_deny_from_hosts(); - - // TorrentPier begin - else if (time() - m_read_db_files_time > m_config.m_read_files_interval) - // TorrentPier end - - read_db_files(); - else if (time() - m_read_db_users_time > m_config.m_read_db_interval) - read_db_users(); - else if (m_config.m_write_db_interval && time() - m_write_db_files_time > m_config.m_write_db_interval) - write_db_files(); - else if (m_config.m_write_db_interval && time() - m_write_db_users_time > m_config.m_write_db_interval) - write_db_users(); - } - write_db_files(); - write_db_users(); - unlink(m_config.m_pid_file.c_str()); - return 0; -} - -void Cserver::accept(const Csocket& l) -{ - // TorrentPier begin - sockaddr_storage a; - while (1) - { - socklen_t cb_a = sizeof(sockaddr_storage); - // TorrentPier end - - Csocket s = ::accept(l, reinterpret_cast(&a), &cb_a); - if (s == SOCKET_ERROR) - { - if (WSAGetLastError() == WSAECONNABORTED) - continue; - if (WSAGetLastError() != WSAEWOULDBLOCK) - std::cerr << "accept failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; - break; - } - - // TorrentPier begin - if (a.ss_family == AF_INET) { - sockaddr_in *b = reinterpret_cast(&a); - - t_deny_from_hosts::const_iterator i = m_deny_from_hosts.lower_bound(ntohl(b->sin_addr.s_addr)); - if (i != m_deny_from_hosts.end() && ntohl(b->sin_addr.s_addr) >= i->second.begin) - { - m_stats.rejected_tcp++; - continue; - } - m_stats.accepted_tcp4++; - } else if (a.ss_family == AF_INET6) m_stats.accepted_tcp6++; - // TorrentPier end - - m_stats.accepted_tcp++; - if (s.blocking(false)) - std::cerr << "ioctlsocket failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; - std::auto_ptr connection(new Cconnection(this, s, a)); - connection->process_events(EPOLLIN); - if (connection->s() != INVALID_SOCKET) - { - m_connections.push_back(connection.release()); - m_epoll.ctl(EPOLL_CTL_ADD, m_connections.back().s(), EPOLLIN | EPOLLOUT | EPOLLPRI | EPOLLERR | EPOLLHUP | EPOLLET, &m_connections.back()); - } - } -} - -std::string Cserver::insert_peer(const Ctracker_input& v, bool udp, t_user* user) -{ - if (m_use_sql && m_config.m_log_announce) - { - m_announce_log_buffer += Csql_query(m_database, "(?,?,?,?,?,?,?,?,?,?),") - .p(ntohl(v.m_ipa)).p(ntohs(v.m_port)).p(v.m_event).p(v.m_info_hash).p(v.m_peer_id).p(v.m_downloaded).p(v.m_left).p(v.m_uploaded).p(user ? user->uid : 0).p(time()).read(); - } - if (!m_config.m_offline_message.empty()) - return m_config.m_offline_message; - - // TorrentPier begin - if (!m_config.m_auto_register && !file(v.m_info_hash)) - return bts_unregistered_torrent; - - t_file& file = m_files[v.m_info_hash]; - - if (!m_config.m_anonymous_announce && !user && file.dl_percent >= 0) - return bts_unregistered_torrent_pass; - - std::string xbt_error = ""; - if (v.m_left && v.m_event != Ctracker_input::e_paused && user && !user->can_leech && !m_config.m_free_leech) - /*if (xbt_error.empty())*/ xbt_error = bts_can_not_leech; - if (user && user->user_active == 0) //unactive - xbt_error = bts_disabled; - if (!file.ctime) - file.ctime = time(); - if (v.m_left && v.m_event != Ctracker_input::e_paused && - user && user->wait_time && file.ctime + user->wait_time > time() && !m_config.m_free_leech) - /*return*/ if (xbt_error.empty()) xbt_error = bts_wait_time; - - t_peers::key_type peer_key = v.m_peer_id; - t_peer* i = find_ptr(file.peers, peer_key); - if (i) - { - if (i->xbt_error_empty) - { - (i->left != e_seeder ? file.leechers : file.seeders)--; - if (t_user* old_user = find_user_by_uid(i->uid)) - (i->left == e_downloader ? old_user->incompletes : old_user->completes)--; - } - - file.speed_ul -= i->speed_ul, file.speed_dl -= i->speed_dl; - } - - if (i && i->xbt_error_empty) { } - else if (v.m_left && v.m_event != Ctracker_input::e_paused && - user && user->torrents_limit && user->incompletes >= user->torrents_limit && !m_config.m_free_leech) - { - /*return*/ if (xbt_error.empty()) xbt_error = bts_torrents_limit_reached; - } - else if (v.m_left && v.m_event != Ctracker_input::e_paused && - user && user->peers_limit && !m_config.m_free_leech) - { - int c = 0, a = 0; - BOOST_FOREACH(t_peers::reference j, file.peers) { - c += j.second.left == e_downloader && j.second.uid == user->uid && j.second.xbt_error_empty; - a += j.second.uid == user->uid && j.second.xbt_error_empty; - } - if (c >= user->peers_limit || a >= user->peers_limit * 3) - /*return*/ if (xbt_error.empty()) xbt_error = bts_peers_limit_reached; - } - - long long downloaded = 0, downloaded_db = 0, downspeed = 0; - long long uploaded = 0, upspeed = 0; - long long bonus = 0; - long long rel = 0; - long long ul_gdc = 0, ul_gdc_16k = 0; - int ul_gdc_count = 0, ul_16k_count = 0, ul_eq_dl_count = 0; - - bool ipv6set = v.m_ipv6set && (v.m_family == AF_INET6 || m_config.m_trust_ipv6); - - if (m_use_sql && user && file.fid) - { - - long long timespent = 0; - if (i - // && boost::equals(i->peer_id, v.m_peer_id) - && v.m_downloaded >= i->downloaded - && v.m_uploaded >= i->uploaded) - { - downloaded = v.m_downloaded - i->downloaded; - uploaded = v.m_uploaded - i->uploaded; - - if( downloaded > 100000000000ll || uploaded > 100000000000ll ) { - downloaded = uploaded = 0; // anti-hack - if (xbt_error.empty()) xbt_error = bts_banned_client; - } - timespent = time() - i->mtime; - if ((timespent << 1) > m_config.m_announce_interval) - { - upspeed = uploaded / timespent; - downspeed = downloaded / timespent; - } - ul_gdc_count = i->ul_gdc_count; - ul_16k_count = i->ul_16k_count; - ul_gdc_16k = i->ul_gdc_16k; - ul_eq_dl_count = i->ul_eq_dl_count; - if( uploaded && m_config.m_gdc ) - { - ul_gdc_count++; - if (uploaded == downloaded) ul_eq_dl_count++; - long long block = 16384; - if( (uploaded % block) == 0ll ) - { - ul_16k_count++; - if( ul_16k_count > 1 ) - ul_gdc_16k = gcd(uploaded, ul_gdc_16k); - else - ul_gdc_16k = uploaded; - } - if( ul_gdc_count == ul_16k_count ) - ul_gdc = ul_gdc_16k; - else - { - if( ul_gdc_count > 1 ) - ul_gdc = gcd(uploaded, i->ul_gdc); - else - ul_gdc = uploaded; - } - } - else - { - ul_gdc = i->ul_gdc; - } - - downloaded_db = (m_config.m_free_leech || file.dl_percent<0) ? 0 : (downloaded * file.dl_percent /100); - - if (user->uid == file.tor_poster_id) - rel = uploaded; - else if (!v.m_left && file.seeders == 1) - bonus = 1; - - // TorrentPier: bb_bt_users_dl_status - int new_status = v.m_left ? 0 : 1; - if (user->uid == file.tor_poster_id) new_status = -1; - if (new_status != i->dl_status && file.tor_topic_id) { - Csql_query q(m_database, "(?,?,?),"); // topic_id,user_id,user_status,update_time - q.p(file.tor_topic_id); // topic_id - q.p(user->uid); // user_id - q.p(new_status); - m_users_dl_status_buffer += q.read(); - i->dl_status = new_status; - } - - // TorrentPier: bb_bt_tor_dl_stat - if (uploaded || downloaded) { - Csql_query q(m_database, "(?,?,?,?,?,?),"); // torrent_id, user_id, attach_id, t_up_total, t_down_total - q.p(file.fid); // torrent_id - q.p(user->uid); // user_id - q.p(file.tor_attach_id); // attach_id - q.p(uploaded); - q.p(downloaded_db); - q.p(bonus ? uploaded * bonus / 100 : 0); - m_tor_dl_stat_buffer += q.read(); - } - - // TorrentPier: bb_cheat_log - long long cheat = (long long) m_config.m_cheat_upload * 1024 * 1024 * 1024; - if (uploaded > cheat) { - Csql_query q(m_database, "(?,?,?,?),"); // torrent_id, user_id, attach_id, t_up_total, t_down_total - q.p(user->uid); // user_id - q.p(uploaded); - q.p(hex_encode(8, ntohl(v.m_ipa))); - q.p(time()); - m_cheat_buffer += q.read(); - } - } - Csql_query q(m_database, "(?,?,?,?,?,?,?,?,?,?, ?,?,?,?, ?,?,?,?,?,?),"); - - int cleanup_interval = static_cast(2.5 * m_config.m_announce_interval); - int min_cleanup = 3900; // 65 min - if( cleanup_interval < min_cleanup ) cleanup_interval = min_cleanup; - - // TorrentPier - std::string port_st, ip_st, peer_hash; - port_st = ntohs(v.m_port); - ip_st = hex_encode(8, ntohl(v.m_ipa)); - peer_hash = md5(v.m_info_hash+v.m_passkey+port_st+ip_st); - - q.p(file.fid); // torrent_id mediumint(8) unsigned NOT NULL default '0' - q.p(v.m_peer_id); - q.p(peer_hash); - q.p(user->uid); // user_id mediumint(9) NOT NULL default '0' - q.p(hex_encode(8, ntohl(v.m_ipa))); // ip char(8) binary NOT NULL default '0' - q.p(const_memory_range(v.m_ipv6bin, ipv6set ? 16 : 0)); // ipv6 varchar(32) - q.p(ntohs(v.m_port)); // port smallint(5) unsigned NOT NULL default '0' - q.p(uploaded); // uploaded bigint(20) unsigned NOT NULL default '0' - q.p(downloaded_db); // downloaded bigint(20) unsigned NOT NULL default '0' - q.p(v.m_left && v.m_event != Ctracker_input::e_paused ? 0 : 1); // seeder tinyint(1) NOT NULL default '0' - q.p(user->uid==file.tor_poster_id), // releaser - q.p(v.m_left ? (v.m_left>=file.tor_size ? 0 : ((file.tor_size-v.m_left)*100/file.tor_size)) : v.m_uploaded); // complete_percent bigint(20) unsigned NOT NULL default '0' - q.p(upspeed); // speed_up mediumint(8) unsigned NOT NULL default '0' - q.p(downspeed); // speed_down mediumint(8) unsigned NOT NULL default '0' - q.p(time()); // update_time int(11) NOT NULL default '0' - q.p(xbt_error); - q.p( ul_16k_count*3 > ul_gdc_count*2 ? ul_gdc_16k : ul_gdc ); - q.p(ul_gdc_count); - q.p(ul_16k_count); - q.p(ul_eq_dl_count); - - m_files_users_updates_buffer += q.read(); - - if (downloaded || uploaded) - { - Csql_query q(m_database, "(?,?,?,?,?,?,?),"); - q.p(downloaded_db); - q.p(uploaded); - q.p(user->uid); - q.p(rel); - q.p(bonus ? uploaded / bonus : 0); - q.p(upspeed); - q.p(downspeed); - m_users_updates_buffer += q.read(); - } - - // Double tracker fix - if (v.m_event == Ctracker_input::e_completed && downloaded) - file.completed++, file.completed_inc++; - } - else - { - if (v.m_event == Ctracker_input::e_completed) - file.completed++, file.completed_inc++; - } - - if (v.m_event == Ctracker_input::e_stopped) - file.peers.erase(peer_key); - else - { - t_peer& peer = file.peers[peer_key]; - peer.downloaded = i && v.m_downloaded < i->downloaded ? i->downloaded : v.m_downloaded; - peer.left = v.m_left == 0 ? e_seeder : v.m_event == Ctracker_input::e_paused ? e_incomplete : e_downloader; - // std::copy(v.m_peer_id.begin(), v.m_peer_id.end(), peer.peer_id.begin()); - peer.port = v.m_port; - peer.uid = user ? user->uid : 0; - peer.uploaded = i && v.m_uploaded < i->uploaded ? i->uploaded : v.m_uploaded; - - file.speed_ul += ( peer.speed_ul = upspeed ); - file.speed_dl += ( peer.speed_dl = downspeed ); - - if (xbt_error.empty()) - { - (peer.left != e_seeder ? file.leechers : file.seeders)++; - if (user) - (peer.left == e_downloader ? user->incompletes : user->completes)++; - } - - peer.xbt_error_empty = xbt_error.empty(); - peer.ul_gdc = ul_gdc; - peer.ul_gdc_16k = ul_gdc_16k; - peer.ul_gdc_count = ul_gdc_count; - peer.ul_16k_count = ul_16k_count; - peer.ul_eq_dl_count = ul_eq_dl_count; - - if (ipv6set && v.m_protocol != 4) { - peer.ipv6set = true; - memcpy(peer.ipv6, v.m_ipv6bin, 16); - m_stats.announced_with_ipv6++; - } - - if ((v.m_family == AF_INET || (m_config.m_trust_ipv6 && v.m_ipa != 0)) && v.m_protocol != 6) peer.host_ = v.m_ipa; - - peer.mtime = time(); - } - - // TorrentPier: Fill seeder_last_seen & last_seeder_uid fields - if (user && !v.m_left) - { - file.tor_last_seeder_uid = user->uid; - file.tor_seeder_last_seen = time(); - } - - (udp ? m_stats.announced_udp : m_stats.announced_http)++; - file.dirty = true; - return xbt_error; - // TorrentPier end -} - -std::string Cserver::t_file::select_peers(const Ctracker_input& ti) const -{ - if (ti.m_event == Ctracker_input::e_stopped) - return ""; - - typedef std::vector > t_candidates; - - t_candidates candidates; - BOOST_FOREACH(t_peers::const_reference i, peers) - { - // TorrentPier begin - if (((!ti.m_left || ti.m_event == Ctracker_input::e_paused) && i.second.left != e_downloader) - || !i.second.xbt_error_empty || !i.second.host_ - || boost::equals(i.first, ti.m_peer_id)) - continue; - boost::array v; - memcpy(&v.front(), &i.second.host_, 4); - // TorrentPier end - - memcpy(&v.front() + 4, &i.second.port, 2); - candidates.push_back(v); - } - size_t c = ti.m_num_want < 0 ? 50 : std::min(ti.m_num_want, 50); - std::string d; - d.reserve(300); - if (candidates.size() > c) - { - while (c--) - { - int i = rand() % candidates.size(); - d.append(candidates[i].begin(), candidates[i].end()); - candidates[i] = candidates.back(); - candidates.pop_back(); - } - } - else - { - BOOST_FOREACH(t_candidates::reference i, candidates) - d.append(i.begin(), i.end()); - } - return d; -} - -// TorrentPier begin -std::string Cserver::t_file::select_peers6(const Ctracker_input& ti) const -{ - if (ti.m_event == Ctracker_input::e_stopped) - return ""; - - typedef std::vector > t_candidates; - - t_candidates candidates; - BOOST_FOREACH(t_peers::const_reference i, peers) - { - if (((!ti.m_left || ti.m_event == Ctracker_input::e_paused) && i.second.left != e_downloader) - || !i.second.xbt_error_empty ||!i.second.ipv6set - || boost::equals(i.first, ti.m_peer_id)) - continue; - - boost::array v; - memcpy(&v.front(), i.second.ipv6, 16); - memcpy(&v.front() + 16, &i.second.port, 2); - candidates.push_back(v); - } - size_t c = ti.m_num_want < 0 ? 50 : std::min(ti.m_num_want, 50); - std::string d; - d.reserve(900); - if (candidates.size() > c) - { - while (c--) - { - int i = rand() % candidates.size(); - d.append(candidates[i].begin(), candidates[i].end()); - candidates[i] = candidates.back(); - candidates.pop_back(); - } - } - else - { - BOOST_FOREACH(t_candidates::reference i, candidates) - d.append(i.begin(), i.end()); - } - return d; -} -// TorrentPier end - -Cvirtual_binary Cserver::select_peers(const Ctracker_input& ti) const -{ - const t_file* f = file(ti.m_info_hash); - if (!f) - return Cvirtual_binary(); - // TorrentPier begin - static int rnd = 0; - - long interval = config().m_announce_interval; - if (ti.m_left) { - interval >>= 1; - } else { - int peers = f->seeders + f->leechers + 1; - interval = interval * (peers + f->seeders) / (peers + peers); - } - interval += (++rnd & 63) + (f->fid & 63) - 64; - - if (ti.m_protocol == 6) { // ti.m_family == AF_INET6 && !m_config.m_trust_ipv6) { - std::string peers6 = f->select_peers6(ti); - return Cvirtual_binary((boost::format("d8:completei%de10:incompletei%de8:intervali%de6:peers6%d:%se") - % f->seeders % f->leechers % interval % peers6.size() % peers6).str()); - } else if (ti.m_protocol == 4) { // ti.m_family == AF_INET && !m_config.m_trust_ipv6) { - std::string peers = f->select_peers(ti); - return Cvirtual_binary((boost::format("d8:completei%de10:incompletei%de8:intervali%de5:peers%d:%se") - % f->seeders % f->leechers % interval % peers.size() % peers).str()); - } else { - std::string peers = f->select_peers(ti); - std::string peers6 = f->select_peers6(ti); - return Cvirtual_binary((boost::format("d8:completei%de10:incompletei%de8:intervali%de5:peers%d:%s6:peers6%d:%se") - % f->seeders % f->leechers % interval % peers.size() % peers % peers6.size() % peers6).str()); - } - // TorrentPier end -} - -void Cserver::t_file::clean_up(time_t t, Cserver& server) -{ - for (t_peers::iterator i = peers.begin(); i != peers.end(); ) - { - if (i->second.mtime < t) - { - // TorrentPier begin - if (i->second.xbt_error_empty) - { - (i->second.left != e_seeder ? leechers : seeders)--; - if (t_user* user = server.find_user_by_uid(i->second.uid)) - (i->second.left == e_downloader ? user->incompletes : user->completes)--; - } - /* - if (i->second.uid) - server.m_files_users_updates_buffer += Csql_query(server.m_database, "(0,0,0,0,-1,0,-1,?,?),").p(fid).p(i->second.uid).read(); - */ - speed_ul -= i->second.speed_ul, speed_dl -= i->second.speed_dl; - // TorrentPier end - - peers.erase(i++); - dirty = true; - } - else - i++; - } -} - -void Cserver::clean_up() -{ - // TorrentPier begin - int cleanup_interval = static_cast(2.5 * m_config.m_announce_interval); - if( cleanup_interval < 1800 ) cleanup_interval = 1800; - BOOST_FOREACH(t_files::reference i, m_files) - i.second.clean_up(time() - cleanup_interval, *this); - // TorrentPier end - - m_clean_up_time = time(); -} - -static byte* write_compact_int(byte* w, unsigned int v) -{ - if (v >= 0x200000) - { - *w++ = 0xe0 | (v >> 24); - *w++ = v >> 16; - *w++ = v >> 8; - } - else if (v >= 0x4000) - { - *w++ = 0xc0 | (v >> 16); - *w++ = v >> 8; - } - else if (v >= 0x80) - *w++ = 0x80 | (v >> 8); - *w++ = v; - return w; -} - -Cvirtual_binary Cserver::scrape(const Ctracker_input& ti) -{ - if (m_use_sql && m_config.m_log_scrape) - { - Csql_query q(m_database, "(?,?,?),"); - q.p(ntohl(ti.m_ipa)); - if (ti.m_info_hash.empty()) - q.p_raw(const_memory_range("null")); - else - q.p(ti.m_info_hash); - q.p(time()); - m_scrape_log_buffer += q.read(); - } - std::string d; - d += "d5:filesd"; - if (ti.m_info_hashes.empty()) - { - m_stats.scraped_full++; - if (ti.m_compact) - { - Cvirtual_binary d; - byte* w = d.write_start(32 * m_files.size() + 1); - *w++ = 'x'; - BOOST_FOREACH(t_files::reference i, m_files) - { - if (!i.second.leechers && !i.second.seeders) - continue; - memcpy(w, i.first.data(), i.first.size()); - w += i.first.size(); - w = write_compact_int(w, i.second.seeders); - w = write_compact_int(w, i.second.leechers); - w = write_compact_int(w, std::min(i.second.completed, 1)); - } - d.resize(w - d); - return d; - } - d.reserve(90 * m_files.size()); - BOOST_FOREACH(t_files::reference i, m_files) - { - if (i.second.leechers || i.second.seeders) - d += (boost::format("20:%sd8:completei%de10:incompletei%dee") % i.first % i.second.seeders % i.second.leechers).str(); - } - } - else - { - m_stats.scraped_http++; - BOOST_FOREACH(Ctracker_input::t_info_hashes::const_reference j, ti.m_info_hashes) - { - if (t_file* i = find_ptr(m_files, j)) - d += (boost::format("20:%sd8:completei%de10:incompletei%dee") % j % i->seeders % i->leechers).str(); - } - } - d += "e"; - if (m_config.m_scrape_interval) - d += (boost::format("5:flagsd20:min_request_intervali%dee") % m_config.m_scrape_interval).str(); - d += "e"; - return Cvirtual_binary(d); -} - -void Cserver::read_db_deny_from_hosts() -{ - m_read_db_deny_from_hosts_time = time(); - if (!m_use_sql) - return; - try - { - Csql_result result = Csql_query(m_database, "SELECT begin, end FROM ?").p_name(table_name(table_deny_from_hosts)).execute(); - BOOST_FOREACH(t_deny_from_hosts::reference i, m_deny_from_hosts) - i.second.marked = true; - for (Csql_row row; row = result.fetch_row(); ) - { - t_deny_from_host& deny_from_host = m_deny_from_hosts[row[1].i()]; - deny_from_host.marked = false; - deny_from_host.begin = row[0].i(); - } - for (t_deny_from_hosts::iterator i = m_deny_from_hosts.begin(); i != m_deny_from_hosts.end(); ) - { - if (i->second.marked) - m_deny_from_hosts.erase(i++); - else - i++; - } - } - catch (Cdatabase::exception&) - { - } -} - -void Cserver::read_db_files() -{ - m_read_db_files_time = time(); - if (m_use_sql) - read_db_files_sql(); - else if (!m_config.m_auto_register) - { - std::set new_files; - std::ifstream is("xbt_files.txt"); - std::string s; - while (getline(is, s)) - { - s = hex_decode(s); - if (s.size() != 20) - continue; - m_files[s]; - new_files.insert(s); - } - for (t_files::iterator i = m_files.begin(); i != m_files.end(); ) - { - if (!new_files.count(i->first)) - m_files.erase(i++); - else - i++; - } - } -} - -// TorrentPier begin -void Cserver::read_db_files_sql() -{ - try - { - Csql_query q(m_database); - if (!m_config.m_auto_register) - { - // XBT read only new torrents, so we need to mark deleted in "_del" table - q = "SELECT rpad(info_hash,20,' '), ?, is_del, dl_percent FROM "+table_name(table_files)+"_del"; - q.p_name(column_name(column_files_fid)); - Csql_result result = q.execute(); - for (Csql_row row; row = result.fetch_row(); ) - { - // if (row[0].size() != 20) continue; - // fix - t_files::iterator i = m_files.find(row[0].s()); - if (i != m_files.end()) - { - if (row[2].i()) - { - for (t_peers::iterator j = i->second.peers.begin(); j != i->second.peers.end(); j++) - { - t_user* user = j->second.uid ? find_user_by_uid(j->second.uid) : NULL; - if (user && j->second.xbt_error_empty) - (j->second.left == e_downloader ? user->incompletes : user->completes)--; - } - m_files.erase(i); - } else { - i->second.dl_percent = row[3].i(); - } - } - // fix - q = "DELETE FROM "+table_name(table_files)+"_del WHERE ? = ?"; - q.p_name(column_name(column_files_fid)); - q.p(row[1].i()); - q.execute(); - } - } - if (m_files.empty()) - m_database.query("UPDATE bb_bt_tracker_snap SET " - + column_name(column_files_leechers) + " = 0, " - + column_name(column_files_seeders) + " = 0, speed_up=0, speed_down=0"); - else if (m_config.m_auto_register) - return; - q = "SELECT rpad(bt.info_hash,20,' '), bt.?, bt.?, bt.reg_time, bt.size, bt.attach_id, bt.topic_id, bt.poster_id, " - + column_name(column_files_dl_percent) + " FROM ? bt WHERE reg_time >= ?"; - q.p_name(column_name(column_files_completed)); - q.p_name(column_name(column_files_fid)); - q.p_name(table_name(table_files)); - q.p(m_fid_end); - Csql_result result = q.execute(); - for (Csql_row row; row = result.fetch_row(); ) - { - m_fid_end = std::max(m_fid_end, static_cast(row[3].i()) + 1); - if (row[0].size() != 20 || m_files.find(row[0].s()) != m_files.end()) - continue; - t_file& file = m_files[row[0].s()]; - if (file.fid) - continue; - file.completed = row[1].i(); - file.dirty = false; - file.fid = row[2].i(); - file.ctime = row[3].i(); - file.tor_size = row[4].i(); - file.tor_attach_id = row[5].i(); - file.tor_topic_id = row[6].i(); - file.tor_poster_id = row[7].i(); - file.dl_percent = row[8].i(); - } - } - catch (Cdatabase::exception&) - { - } -} -// TorrentPier end - -void Cserver::read_db_users() -{ - m_read_db_users_time = time(); - if (!m_use_sql) - return; - try - { - // TorrentPier begin - Csql_query q(m_database, "SELECT bt.?, auth_key, " + column_name(column_users_can_leech) + ", " - + column_name(column_users_torrents_limit) + ", u.user_active FROM ? bt LEFT JOIN bb_users u ON (u.user_id = bt.user_id)"); - // TorrentPier end - - q.p_name(column_name(column_users_uid)); - q.p_name(table_name(table_users)); - Csql_result result = q.execute(); - BOOST_FOREACH(t_users::reference i, m_users) - i.second.marked = true; - m_users_torrent_passes.clear(); - for (Csql_row row; row = result.fetch_row(); ) - { - t_user& user = m_users[row[0].i()]; - user.marked = false; - - // TorrentPier begin - user.uid = row[0].i(); - user.wait_time = 0; - user.torrents_limit = row[3].i(); - user.peers_limit = 2; // # of IP addresses user can leech from - user.can_leech = row[2].i(); - user.user_active = row[4].i(); - if (row[1].size()) { - user.passkey = row[1].s(); - m_users_torrent_passes[user.passkey] = &user; - } - // TorrentPier end - } - for (t_users::iterator i = m_users.begin(); i != m_users.end(); ) - { - if (i->second.marked) - m_users.erase(i++); - else - i++; - } - } - catch (Cdatabase::exception&) - { - } -} - -void Cserver::write_db_files() -{ - m_write_db_files_time = time(); - if (!m_use_sql) - return; - try - { - std::string buffer; - BOOST_FOREACH(t_files::reference i, m_files) - { - t_file& file = i.second; - if (!file.dirty) - continue; - if (!file.fid) - { - // TorrentPier begin - Csql_query(m_database, "INSERT INTO ? (info_hash, reg_time) VALUES (?, unix_timestamp())").p_name(table_name(table_files)).p(i.first).execute(); - // TorrentPier end - - file.fid = m_database.insert_id(); - } - - // TorrentPier begin - Csql_query q(m_database, "(?,?,?,?,?),"); - q.p(file.completed_inc); file.completed_inc = 0; - q.p(file.fid); - q.p(file.tor_seeder_last_seen); file.tor_seeder_last_seen = 0; - q.p(file.speed_ul); - q.p(file.speed_dl); - buffer += q.read(); - // TorrentPier end - - file.dirty = false; - } - if (!buffer.empty()) - { - buffer.erase(buffer.size() - 1); - - // TorrentPier begin - m_database.query("INSERT INTO " + table_name(table_files) + " (" - + column_name(column_files_completed) + ", " - + column_name(column_files_fid) - + ", seeder_last_seen, speed_up, speed_down) VALUES " - + buffer - + " ON DUPLICATE KEY UPDATE speed_up = values(speed_up), speed_down = values(speed_down)," - + " " + column_name(column_files_completed) + " = " + column_name(column_files_completed) + " + values(" + column_name(column_files_completed) + ")," - + " seeder_last_seen = values(seeder_last_seen)" - ); - // TorrentPier end - } - } - catch (Cdatabase::exception&) - { - } - if (!m_announce_log_buffer.empty()) - { - try - { - m_announce_log_buffer.erase(m_announce_log_buffer.size() - 1); - m_database.query("INSERT DELAYED INTO " + table_name(table_announce_log) + " (ipa, port, event, info_hash, peer_id, downloaded, left0, uploaded, uid, mtime) VALUES " + m_announce_log_buffer); - } - catch (Cdatabase::exception&) - { - } - m_announce_log_buffer.erase(); - } - if (!m_scrape_log_buffer.empty()) - { - try - { - m_scrape_log_buffer.erase(m_scrape_log_buffer.size() - 1); - m_database.query("INSERT DELAYED INTO " + table_name(table_scrape_log) + " (ipa, info_hash, mtime) VALUES " + m_scrape_log_buffer); - } - catch (Cdatabase::exception&) - { - } - m_scrape_log_buffer.erase(); - } -} - -// TorrentPier begin -void Cserver::write_db_users() -{ - m_write_db_users_time = time(); - - if (!m_use_sql) - return; - - if (!m_files_users_updates_buffer.empty()) - { - m_files_users_updates_buffer.erase(m_files_users_updates_buffer.size() - 1); - try - { - m_database.query("INSERT INTO " + table_name(table_files_users) - + " (topic_id, peer_id, peer_hash, user_id, ip, ipv6, port, uploaded, downloaded, seeder, releaser, complete_percent, speed_up, speed_down, update_time, xbt_error, ul_gdc, ul_gdc_c, ul_16k_c, ul_eq_dl) VALUES " - + m_files_users_updates_buffer - + " on duplicate key update" - + " topic_id = values(topic_id)," - + " peer_id = values(peer_id)," - + " peer_hash = values(peer_hash)," - + " user_id = values(user_id)," - + " ip = values(ip), ipv6 = values(ipv6)," - + " port = values(port)," - + " uploaded = uploaded + values(uploaded)," - + " downloaded = downloaded + values(downloaded)," - + " complete_percent = values(complete_percent)," - + " seeder = values(seeder)," - + " releaser = values(releaser)," - + " speed_up = values(speed_up)," - + " speed_down = values(speed_down)," - + " up_add = up_add + values(uploaded)," - + " down_add = down_add + values(downloaded)," - + " update_time = values(update_time)," - + " xbt_error = values(xbt_error), ul_gdc = values(ul_gdc), ul_gdc_c = values(ul_gdc_c), ul_16k_c = values(ul_16k_c), ul_eq_dl = values(ul_eq_dl)"); - } - catch (Cdatabase::exception&) - { - } - m_files_users_updates_buffer.erase(); - } - - if (!m_users_updates_buffer.empty()) - { - m_users_updates_buffer.erase(m_users_updates_buffer.size() - 1); - try - { - m_database.query("INSERT INTO " + table_name(table_users) + " (u_down_total, u_up_total, " + column_name(column_users_uid) + ", u_up_release, u_up_bonus, max_up_speed, max_down_speed) VALUES " - + m_users_updates_buffer - + " on duplicate key update" - + " u_down_total = u_down_total + values(u_down_total)," - + " u_up_total = u_up_total + values(u_up_total)," - + " u_up_release = u_up_release + values(u_up_release)," - + " u_up_bonus = u_up_bonus + values(u_up_bonus)," - + " max_up_speed = GREATEST(max_up_speed, values(max_up_speed))," - + " max_down_speed = GREATEST(max_down_speed, values(max_down_speed))," - + " u_down_today = u_down_today + values(u_down_total)," - + " u_up_today = u_up_today + values(u_up_total)," - + " u_release_today = u_release_today + values(u_up_release)," - + " u_bonus_today = u_bonus_today + values(u_up_bonus)," - + " u_up_speed_today = GREATEST(u_up_speed_today, values(max_up_speed))," - + " u_down_speed_today = GREATEST(u_down_speed_today, values(max_down_speed))"); - } - catch (Cdatabase::exception&) - { - } - m_users_updates_buffer.erase(); - } - - if (!m_users_dl_status_buffer.empty()) - { - m_users_dl_status_buffer.erase(m_users_dl_status_buffer.size() - 1); - try - { - m_database.query("INSERT INTO bb_bt_dlstatus_main (topic_id,user_id,user_status) VALUES" - + m_users_dl_status_buffer - + " on duplicate key update" - + " user_status = values(user_status)"); - } - catch (Cdatabase::exception&) - { - } - m_users_dl_status_buffer.erase(); - } - - if (!m_tor_dl_stat_buffer.empty()) - { - m_tor_dl_stat_buffer.erase(m_tor_dl_stat_buffer.size() - 1); - try - { - m_database.query("INSERT INTO bb_bt_torrent_activity(user_id, topic_id, torrent_upload, torrent_download, torrent_speed_up, torrent_speed_down, torrent_dl_status, torrent_bonus, torrent_status, torrent_all_download, torrent_time_st, torrent_time) VALUES" - + m_tor_dl_stat_buffer - + " on duplicate key update" - + " torrent_upload = torrent_upload + values(torrent_upload)," - + " torrent_speed_up = GREATEST(torrent_speed_up, values(torrent_speed_up))," - + " torrent_speed_down = GREATEST(torrent_speed_down, values(torrent_speed_down))," - + " torrent_download = torrent_download + values(torrent_download)," - + " torrent_all_download = torrent_all_download + values(torrent_all_download)," - + " torrent_time = torrent_time + values(torrent_time)," - + " torrent_status = GREATEST(torrent_status, values(torrent_status))," - + " torrent_bonus = torrent_bonus + values(torrent_bonus)"); - } - catch (Cdatabase::exception&) - { - } - m_tor_dl_stat_buffer.erase(); - } - - // Cheat - if (!m_cheat_buffer.empty()) - { - m_cheat_buffer.erase(m_cheat_buffer.size() - 1); - try - { - m_database.query("INSERT INTO bb_bt_cheat_log (cheat_user_id, cheat_uploaded, cheat_ip, cheat_log_time) VALUES" - + m_cheat_buffer); - } - catch (Cdatabase::exception&) - { - } - m_cheat_buffer.erase(); - } -} -// TorrentPier end - -void Cserver::read_config() -{ - if (m_use_sql) - { - try - { - Csql_result result = m_database.query("SELECT name, value FROM " + table_name(table_config) + " WHERE value is not null"); - Cconfig config; - for (Csql_row row; row = result.fetch_row(); ) - { - if (config.set(row[0].s(), row[1].s())) - std::cerr << "unknown config name: " << row[0].s() << std::endl; - } - config.load(m_conf_file); - if (config.m_torrent_pass_private_key.empty()) - { - config.m_torrent_pass_private_key = generate_random_string(27); - Csql_query(m_database, "INSERT INTO xbt_config (name, value) VALUES ('torrent_pass_private_key', ?)").p(config.m_torrent_pass_private_key).execute(); - } - m_config = config; - } - catch (Cdatabase::exception&) - { - } - } - else - { - Cconfig config; - if (!config.load(m_conf_file)) - m_config = config; - } - - // TorrentPier begin - if (m_config.m_listen_ipas.empty()) - m_config.m_listen_ipas.insert("*"); - if (m_config.m_listen_ports.empty()) - m_config.m_listen_ports.insert("2710"); - // TorrentPier end - - m_read_config_time = time(); -} - -void Cserver::t_file::debug(std::ostream& os) const -{ - BOOST_FOREACH(t_peers::const_reference i, peers) - { - // TorrentPier begin - os << "" + Csocket::inet_ntoa(i.second.host_) - << "" << (i.second.ipv6set ? hex_encode(const_memory_range(i.second.ipv6,16)) : "") - // TorrentPier end - - << "" << ntohs(i.second.port) - << "" << i.second.uid - << "" << i.second.left - << "" << ::time(NULL) - i.second.mtime - - // TorrentPier begin - << "" << hex_encode(const_memory_range(i.first.c_str(), 20)); - // TorrentPier end - } -} - -std::string Cserver::debug(const Ctracker_input& ti) const -{ - std::ostringstream os; - os << "XBT Tracker"; - int leechers = 0; - int seeders = 0; - int torrents = 0; - os << ""; - if (ti.m_info_hash.empty()) - { - BOOST_FOREACH(t_files::const_reference i, m_files) - { - if (!i.second.leechers && !i.second.seeders) - continue; - leechers += i.second.leechers; - seeders += i.second.seeders; - torrents++; - os << "
" << i.second.fid - << "" << hex_encode(i.first) << "" - << "" << (i.second.dirty ? '*' : ' ') - << "" << i.second.leechers - << "" << i.second.seeders; - } - } - else - { - if (const t_file* i = find_ptr(m_files, ti.m_info_hash)) - i->debug(os); - } - os << "
"; - return os.str(); -} - -std::string Cserver::statistics() const -{ - std::ostringstream os; - os << "XBT Tracker"; - int leechers = 0; - int seeders = 0; - int torrents = 0; - BOOST_FOREACH(t_files::const_reference i, m_files) - { - leechers += i.second.leechers; - seeders += i.second.seeders; - torrents += i.second.leechers || i.second.seeders; - } - time_t t = time(); - os << "
leechers" << leechers - << "
seeders" << seeders - << "
peers" << leechers + seeders - << "
torrents" << torrents - << "
" - << "
accepted tcp" << m_stats.accepted_tcp - - // TorrentPier begin - << "
accepted tcp4" << m_stats.accepted_tcp4 << "" << m_stats.accepted_tcp4 * 100 / m_stats.accepted_tcp << " %" - << "
accepted tcp6" << m_stats.accepted_tcp6 << "" << m_stats.accepted_tcp6 * 100 / m_stats.accepted_tcp << " %" - // TorrentPier end - - << "
rejected tcp" << m_stats.rejected_tcp - << "
announced" << m_stats.announced(); - if (m_stats.announced()) - { - os << "
announced http " << m_stats.announced_http << "" << m_stats.announced_http * 100 / m_stats.announced() << " %" - << "
announced udp" << m_stats.announced_udp << "" << m_stats.announced_udp * 100 / m_stats.announced() << " %" - - // TorrentPier begin - << "
with &ipv6=" << m_stats.announced_with_ipv6 << "" << m_stats.announced_with_ipv6 * 100 / m_stats.announced() << " %"; - // TorrentPier end - } - os << "
scraped full" << m_stats.scraped_full - << "
scraped" << m_stats.scraped(); - if (m_stats.scraped()) - { - os << "
scraped http" << m_stats.scraped_http << "" << m_stats.scraped_http * 100 / m_stats.scraped() << " %" - << "
scraped udp" << m_stats.scraped_udp << "" << m_stats.scraped_udp * 100 / m_stats.scraped() << " %"; - } - os << "
" - << "
up time" << duration2a(time() - m_stats.start_time) - << "
" - << "
anonymous connect" << m_config.m_anonymous_connect - << "
anonymous announce" << m_config.m_anonymous_announce - << "
anonymous scrape" << m_config.m_anonymous_scrape - << "
auto register" << m_config.m_auto_register - << "
full scrape" << m_config.m_full_scrape - - // TorrentPier begin - << "
free leech" << m_config.m_free_leech - << "
announce interval" << m_config.m_announce_interval - // TorrentPier end - - << "
read config time" << t - m_read_config_time << " / " << m_config.m_read_config_interval - << "
clean up time" << t - m_clean_up_time << " / " << m_config.m_clean_up_interval - - // TorrentPier begin - << "
read db files time" << t - m_read_db_files_time << " / " << m_config.m_read_files_interval; - // TorrentPier end - - if (m_use_sql) - { - os << "
read db users time" << t - m_read_db_users_time << " / " << m_config.m_read_db_interval - << "
write db files time" << t - m_write_db_files_time << " / " << m_config.m_write_db_interval - << "
write db users time" << t - m_write_db_users_time << " / " << m_config.m_write_db_interval; - } - os << "
"; - return os.str(); -} - -Cserver::t_user* Cserver::find_user_by_torrent_pass(const std::string& v, const std::string& info_hash) -{ - // TorrentPier begin - if (v.size() == 32) if (t_user* user = find_user_by_uid(read_int(4, hex_decode(v.substr(0, 8))))) - { - if (Csha1((boost::format("%s %s %d %s") % m_config.m_torrent_pass_private_key % user->passkey % user->uid % info_hash).str()).read().substr(0, 12) == hex_decode(v.substr(8))) - return user; - } - // TorrentPier end - - t_user** i = find_ptr(m_users_torrent_passes, v); - return i ? *i : NULL; -} - -Cserver::t_user* Cserver::find_user_by_uid(int v) -{ - return find_ptr(m_users, v); -} - -void Cserver::sig_handler(int v) -{ - switch (v) - { - case SIGTERM: - g_sig_term = true; - break; - } -} - -void Cserver::term() -{ - g_sig_term = true; -} - -std::string Cserver::column_name(int v) const -{ - switch (v) - { - case column_files_completed: - return m_config.m_column_files_completed; - case column_files_leechers: - return m_config.m_column_files_leechers; - case column_files_seeders: - return m_config.m_column_files_seeders; - case column_files_fid: - return m_config.m_column_files_fid; - case column_users_uid: - return m_config.m_column_users_uid; - - // TorrentPier begin - case column_files_dl_percent: - return m_config.m_column_files_dl_percent; - case column_users_can_leech: - return m_config.m_column_users_can_leech; - case column_users_torrents_limit: - return m_config.m_column_users_torrents_limit; - // TorrentPier end - - } - assert(false); - return ""; -} - -std::string Cserver::table_name(int v) const -{ - switch (v) - { - case table_announce_log: - return m_config.m_table_announce_log.empty() ? m_table_prefix + "announce_log" : m_config.m_table_announce_log; - case table_config: - return m_table_prefix + "config"; - case table_deny_from_hosts: - return m_config.m_table_deny_from_hosts.empty() ? m_table_prefix + "deny_from_hosts" : m_config.m_table_deny_from_hosts; - case table_files: - return m_config.m_table_files.empty() ? m_table_prefix + "files" : m_config.m_table_files; - case table_files_users: - return m_config.m_table_files_users.empty() ? m_table_prefix + "files_users" : m_config.m_table_files_users; - case table_scrape_log: - return m_config.m_table_scrape_log.empty() ? m_table_prefix + "scrape_log" : m_config.m_table_scrape_log; - case table_users: - return m_config.m_table_users.empty() ? m_table_prefix + "users" : m_config.m_table_users; - } - assert(false); - return ""; -} - -int Cserver::test_sql() -{ - if (!m_use_sql) - return 0; - try - { - /*mysql_get_server_version(m_database.handle()); - //xbtt - m_database.query("select id, ipa, port, event, info_hash, peer_id, downloaded, left0, uploaded, uid, mtime from " + table_name(table_announce_log) + " where 0"); - m_database.query("select name, value from " + table_name(table_config) + " where 0"); - \m_database.query("select begin, end from " + table_name(table_deny_from_hosts) + " where 0"); - m_database.query("select id, ipa, info_hash, uid, mtime from " + table_name(table_scrape_log) + " where 0"); - - // TorrentPier begin - m_database.query("select peer_hash, user_id, ip, ipv6, port, uploaded, downloaded, seeder, speed_up, speed_down, update_time, ul_gdc, ul_gdc_c, ul_16k_c, ul_eq_dl from " + table_name(table_files_users) + " where 0"); // Note: `port_open` is not used any more - m_database.query("select " + column_name(column_users_uid) + ", auth_key, " - + column_name(column_users_can_leech) + " as u_cl, " + column_name(column_users_torrents_limit) - + " as u_tl, u_down_total, u_up_total, u_up_release, u_down_today, u_up_today, u_up_bonus, max_up_speed, max_down_speed from " + table_name(table_users) + " where 0"); - - m_database.query("select bbt.info_hash, bt.seeder, bbt.reg_time, bbt.size, bbt.attach_id, bbt.topic_id, bbt.seeder_last_seen, bt.speed_up, bt.speed_down, bbt.poster_id, " - + column_name(column_files_dl_percent) + " from " + table_name(table_files) + " bbt LEFT JOIN bb_bt_tracker bt ON (bt.topic_id = bbt.topic_id) where 0"); - // TorrentPier: Files deletion table = table_name(table_files) + "_del" suffix - \m_database.query("select rpad(info_hash,20,' '), " + column_name(column_files_fid) - \+ ", is_del, dl_percent from " + table_name(table_files) + " where 0"); - m_database.query("select topic_id,user_id,user_status,last_modified_dlstatus from bb_bt_dlstatus_main where 0"); - m_database.query("select torrent_id,user_id,attach_id,t_up_total,t_down_total,t_bonus_total from bb_bt_tor_dl_stat where 0"); - // TorrentPier end - - m_read_users_can_leech = m_database.query("show columns from " + table_name(table_users) + " like 'can_leech'"); - m_read_users_peers_limit = m_database.query("show columns from " + table_name(table_users) + " like 'peers_limit'"); - m_read_users_torrent_pass = m_database.query("show columns from " + table_name(table_users) + " like 'torrent_pass'"); - m_read_users_torrents_limit = m_database.query("show columns from " + table_name(table_users) + " like 'torrents_limit'"); - m_read_users_wait_time = m_database.query("show columns from " + table_name(table_users) + " like 'wait_time'"); - */ - return 0; - } - catch (Cdatabase::exception&) - { - } - return 1; -} diff --git a/install/xbt/linux/Tracker/server.h b/install/xbt/linux/Tracker/server.h deleted file mode 100644 index 11b082ee6..000000000 --- a/install/xbt/linux/Tracker/server.h +++ /dev/null @@ -1,267 +0,0 @@ -#pragma once - -#include "config.h" -#include "connection.h" -#include "epoll.h" -#include "stats.h" -#include "tcp_listen_socket.h" -#include "tracker_input.h" -#include "udp_listen_socket.h" -#include -#include -#include -#include -#include -#include - -class Cserver -{ -public: - // TorrentPier begin - typedef std::string peer_key_c; - // TorrentPier end - - enum t_complete_status - { - e_seeder, - e_incomplete, - e_downloader, - }; - - struct t_peer - { - t_peer() - { - mtime = 0; - - // TorrentPier begin - dl_status = 0; // TorrentPier: 1 = downloading, 2 = complete - ipv6set = false; - host_ = 0; - // TorrentPier end - } - - long long downloaded; - long long uploaded; - time_t mtime; - int uid; - short port; - t_complete_status left; - - // TorrentPier begin - // boost::array peer_id; - - long long speed_dl; - long long speed_ul; - int dl_status; - bool xbt_error_empty; - // Upload Greatest Common Divisor - long long ul_gdc, ul_gdc_16k; - int ul_gdc_count, ul_16k_count, ul_eq_dl_count; - - bool ipv6set; - // boost::array ipv6; - char ipv6[16]; - int host_; - // TorrentPier end - }; - - typedef std::map t_peers; - - struct t_deny_from_host - { - unsigned int begin; - bool marked; - }; - - struct t_file - { - void clean_up(time_t t, Cserver&); - void debug(std::ostream&) const; - std::string select_peers(const Ctracker_input&) const; - - // TorrentPier begin - std::string select_peers6(const Ctracker_input&) const; - // TorrentPier end - - t_file() - { - completed = 0; - dirty = true; - fid = 0; - leechers = 0; - seeders = 0; - - // TorrentPier begin - completed_inc = 0; - tor_size = 0; - tor_attach_id = tor_topic_id = 0; - tor_seeder_last_seen = 0; - tor_last_seeder_uid = tor_poster_id = 0; - speed_dl = speed_ul = 0; - dl_percent = 100; - // TorrentPier end - } - - t_peers peers; - time_t ctime; - int completed; - int fid; - int leechers; - int seeders; - bool dirty; - - // TorrentPier begin - int completed_inc; - long long tor_size; - int tor_attach_id, tor_topic_id; - time_t tor_seeder_last_seen; - int tor_last_seeder_uid, tor_poster_id; - long long speed_dl, speed_ul; - int dl_percent; - // TorrentPier end - }; - - struct t_user - { - t_user() - { - can_leech = true; - completes = 0; - incompletes = 0; - peers_limit = 0; - torrents_limit = 0; - wait_time = 0; - user_active = 1; - } - - bool can_leech; - bool marked; - int uid; - int completes; - int incompletes; - int peers_limit; - std::string passkey; - int torrents_limit; - int wait_time; - int user_active; - }; - - int test_sql(); - void accept(const Csocket&); - t_user* find_user_by_torrent_pass(const std::string&, const std::string& info_hash); - t_user* find_user_by_uid(int); - void read_config(); - void write_db_files(); - void write_db_users(); - void read_db_deny_from_hosts(); - void read_db_files(); - void read_db_files_sql(); - void read_db_users(); - void clean_up(); - std::string insert_peer(const Ctracker_input&, bool udp, t_user*); - std::string debug(const Ctracker_input&) const; - std::string statistics() const; - Cvirtual_binary select_peers(const Ctracker_input&) const; - Cvirtual_binary scrape(const Ctracker_input&); - int run(); - static void term(); - Cserver(Cdatabase&, const std::string& table_prefix, bool use_sql, const std::string& conf_file); - - const t_file* file(const std::string& id) const - { - return find_ptr(m_files, id); - } - - const Cconfig& config() const - { - return m_config; - } - - long long secret() const - { - return m_secret; - } - - Cstats& stats() - { - return m_stats; - } - - time_t time() const - { - return m_time; - } -private: - enum - { - column_files_completed, - column_files_fid, - column_files_leechers, - column_files_seeders, - column_users_uid, - table_announce_log, - table_config, - table_deny_from_hosts, - table_files, - table_files_users, - table_scrape_log, - table_users, - - // TorrentPier begin - column_files_dl_percent, - column_users_can_leech, - column_users_torrents_limit, - // TorrentPier end - }; - - typedef boost::ptr_list t_connections; - typedef std::list t_tcp_sockets; - typedef std::list t_udp_sockets; - typedef std::map t_files; - typedef std::map t_deny_from_hosts; - typedef std::map t_users; - typedef std::map t_users_torrent_passes; - - static void sig_handler(int v); - std::string column_name(int v) const; - std::string table_name(int) const; - - Cconfig m_config; - Cstats m_stats; - bool m_read_users_can_leech; - bool m_read_users_peers_limit; - bool m_read_users_torrent_pass; - bool m_read_users_torrents_limit; - bool m_read_users_wait_time; - bool m_use_sql; - time_t m_clean_up_time; - time_t m_read_config_time; - time_t m_read_db_deny_from_hosts_time; - time_t m_read_db_files_time; - time_t m_read_db_users_time; - time_t m_time; - time_t m_write_db_files_time; - time_t m_write_db_users_time; - int m_fid_end; - long long m_secret; - t_connections m_connections; - Cdatabase& m_database; - Cepoll m_epoll; - t_deny_from_hosts m_deny_from_hosts; - t_files m_files; - t_users m_users; - t_users_torrent_passes m_users_torrent_passes; - std::string m_announce_log_buffer; - std::string m_conf_file; - std::string m_files_users_updates_buffer; - std::string m_scrape_log_buffer; - std::string m_table_prefix; - std::string m_users_updates_buffer; - - // TorrentPier begin - std::string m_users_dl_status_buffer; - std::string m_tor_dl_stat_buffer; - std::string m_cheat_buffer; - // TorrentPier end -}; diff --git a/install/xbt/linux/Tracker/stats.h b/install/xbt/linux/Tracker/stats.h deleted file mode 100644 index 7570bdc7c..000000000 --- a/install/xbt/linux/Tracker/stats.h +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#include - -class Cstats -{ -public: - Cstats() - { - accepted_tcp = 0; - announced_http = 0; - announced_udp = 0; - rejected_tcp = 0; - scraped_full = 0; - scraped_http = 0; - scraped_udp = 0; - start_time = time(NULL); - - // TorrentPier begin - announced_with_ipv6 = 0; - accepted_tcp4 = 0; - accepted_tcp6 = 0; - // TorrentPier end - } - - long long announced() const - { - return announced_http + announced_udp; - } - - long long scraped() const - { - return scraped_http + scraped_udp; - } - - long long accepted_tcp; - long long announced_http; - long long announced_udp; - long long rejected_tcp; - long long scraped_full; - long long scraped_http; - long long scraped_udp; - time_t start_time; - - // TorrentPier begin - long long announced_with_ipv6; - long long accepted_tcp4; - long long accepted_tcp6; - // TorrentPier end -}; diff --git a/install/xbt/linux/Tracker/stdafx.cpp b/install/xbt/linux/Tracker/stdafx.cpp deleted file mode 100644 index a27b824da..000000000 --- a/install/xbt/linux/Tracker/stdafx.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "stdafx.h" diff --git a/install/xbt/linux/Tracker/stdafx.h b/install/xbt/linux/Tracker/stdafx.h deleted file mode 100644 index 80f2eb108..000000000 --- a/install/xbt/linux/Tracker/stdafx.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef WIN32 -#define FD_SETSIZE 1024 -#define NOMINMAX - -#define atoll _atoi64 -#else -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// TorrentPier begin -#include -// TorrentPier end - -#endif - -typedef unsigned char byte; diff --git a/install/xbt/linux/Tracker/tcp_listen_socket.cpp b/install/xbt/linux/Tracker/tcp_listen_socket.cpp deleted file mode 100644 index ac378b1d0..000000000 --- a/install/xbt/linux/Tracker/tcp_listen_socket.cpp +++ /dev/null @@ -1,20 +0,0 @@ -#include "stdafx.h" -#include "tcp_listen_socket.h" - -#include "server.h" - -Ctcp_listen_socket::Ctcp_listen_socket() -{ - m_server = NULL; -} - -Ctcp_listen_socket::Ctcp_listen_socket(Cserver* server, const Csocket& s) -{ - m_server = server; - m_s = s; -} - -void Ctcp_listen_socket::process_events(int events) -{ - m_server->accept(m_s); -} diff --git a/install/xbt/linux/Tracker/tcp_listen_socket.h b/install/xbt/linux/Tracker/tcp_listen_socket.h deleted file mode 100644 index 94316ff38..000000000 --- a/install/xbt/linux/Tracker/tcp_listen_socket.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "client.h" - -class Cserver; - -class Ctcp_listen_socket: public Cclient -{ -public: - virtual void process_events(int); - Cclient::s; - Ctcp_listen_socket(); - Ctcp_listen_socket(Cserver*, const Csocket&); -}; diff --git a/install/xbt/linux/Tracker/tracker_input.cpp b/install/xbt/linux/Tracker/tracker_input.cpp deleted file mode 100644 index 24e5a8d98..000000000 --- a/install/xbt/linux/Tracker/tracker_input.cpp +++ /dev/null @@ -1,350 +0,0 @@ -#include "stdafx.h" -#include "tracker_input.h" - -#include -#include -#include - -// TorrentPier begin -#ifdef WIN32 - -#define IN6ADDRSZ 16 -#define INADDRSZ 4 -#define INT16SZ 2 - -/* int - * inet_pton4(src, dst) - * like inet_aton() but without all the hexadecimal and shorthand. - * return: - * 1 if `src' is a valid dotted quad, else 0. - * notice: - * does not touch `dst' unless it's returning 1. - * author: - * Paul Vixie, 1996. - */ -static int -inet_pton4(const char *src, unsigned char *dst) -{ - static const char digits[] = "0123456789"; - int saw_digit, octets, ch; - unsigned char tmp[INADDRSZ], *tp; - - saw_digit = 0; - octets = 0; - *(tp = tmp) = 0; - while ((ch = *src++) != '\0') { - const char *pch; - - if ((pch = strchr(digits, ch)) != NULL) { - unsigned int newval = (unsigned int) (*tp * 10 + (pch - digits)); - - if (newval > 255) - return (0); - *tp = newval; - if (! saw_digit) { - if (++octets > 4) - return (0); - saw_digit = 1; - } - } else if (ch == '.' && saw_digit) { - if (octets == 4) - return (0); - *++tp = 0; - saw_digit = 0; - } else - return (0); - } - if (octets < 4) - return (0); - - memcpy(dst, tmp, INADDRSZ); - return (1); -} - -/* int - * inet_pton6(src, dst) - * convert presentation level address to network order binary form. - * return: - * 1 if `src' is a valid [RFC1884 2.2] address, else 0. - * notice: - * (1) does not touch `dst' unless it's returning 1. - * (2) :: in a full address is silently ignored. - * credit: - * inspired by Mark Andrews. - * author: - * Paul Vixie, 1996. - */ -static int -inet_pton6(const char *src, unsigned char *dst) -{ - static const char xdigits_l[] = "0123456789abcdef", - xdigits_u[] = "0123456789ABCDEF"; - unsigned char tmp[IN6ADDRSZ], *tp, *endp, *colonp; - const char *xdigits, *curtok; - int ch, saw_xdigit; - unsigned int val; - - memset((tp = tmp), '\0', IN6ADDRSZ); - endp = tp + IN6ADDRSZ; - colonp = NULL; - /* Leading :: requires some special handling. */ - if (*src == ':') - if (*++src != ':') - return (0); - curtok = src; - saw_xdigit = 0; - val = 0; - while ((ch = *src++) != '\0') { - const char *pch; - - if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL) - pch = strchr((xdigits = xdigits_u), ch); - if (pch != NULL) { - val <<= 4; - val |= (pch - xdigits); - if (val > 0xffff) - return (0); - saw_xdigit = 1; - continue; - } - if (ch == ':') { - curtok = src; - if (!saw_xdigit) { - if (colonp) - return (0); - colonp = tp; - continue; - } - if (tp + INT16SZ > endp) - return (0); - *tp++ = (unsigned char) (val >> 8) & 0xff; - *tp++ = (unsigned char) val & 0xff; - saw_xdigit = 0; - val = 0; - continue; - } - if (ch == '.' && ((tp + INADDRSZ) <= endp) && - inet_pton4(curtok, tp) > 0) { - tp += INADDRSZ; - saw_xdigit = 0; - break; /* '\0' was seen by inet_pton4(). */ - } - return (0); - } - if (saw_xdigit) { - if (tp + INT16SZ > endp) - return (0); - *tp++ = (unsigned char) (val >> 8) & 0xff; - *tp++ = (unsigned char) val & 0xff; - } - if (colonp != NULL) { - /* - * Since some memmove()'s erroneously fail to handle - * overlapping regions, we'll do the shift by hand. - */ - const int n = tp - colonp; - int i; - - for (i = 1; i <= n; i++) { - endp[- i] = colonp[n - i]; - colonp[n - i] = 0; - } - tp = endp; - } - if (tp != endp) - return (0); - memcpy(dst, tmp, IN6ADDRSZ); - return (1); -} - -int my_inet_pton(int af, const char *src, void *dst) -{ - return (inet_pton6(src, (unsigned char *) dst)); -} - -#define inet_pton my_inet_pton - -#endif - -Ctracker_input::Ctracker_input(int family) -// TorrentPier end -{ - m_compact = false; - m_downloaded = 0; - m_event = e_none; - m_ipa = 0; - m_left = 0; - m_port = 0; - m_uploaded = 0; - m_num_want = -1; - - // TorrentPier begin - m_ipv6set = false; - m_family = family; - m_protocol = 0; - // TorrentPier end -} - -void Ctracker_input::set(const std::string& name, const std::string& value) -{ - if (name.empty()) - return; - switch (name[0]) - { - case 'c': - if (name == "compact") - m_compact = atoi(value.c_str()); - break; - case 'd': - if (name == "downloaded") - m_downloaded = atoll(value.c_str()); - break; - case 'e': - if (name == "event") - { - if (value == "completed") - m_event = e_completed; - else if (value == "started") - m_event = e_started; - else if (value == "stopped") - m_event = e_stopped; - else if (value == "paused") - m_event = e_paused; - else - m_event = e_none; - } - break; - case 'i': - if (name == "info_hash" && value.size() == 20) - { - m_info_hash = value; - m_info_hashes.push_back(value); - } - - // TorrentPier begin - else if (name == "ip" || name == "ipv4") - m_ipa = inet_addr(value.c_str()); - else if (name == "ipv6") { - m_ipv6set = inet_pton(AF_INET6, value.c_str(), m_ipv6bin); - if (m_ipv6bin[0] == '\xFE' && m_ipv6bin[1] == '\x80') m_ipv6set = false; - } - // TorrentPier end - - break; - case 'l': - if (name == "left") - m_left = atoll(value.c_str()); - break; - case 'n': - if (name == "numwant") - m_num_want = atoi(value.c_str()); - break; - case 'p': - if (name == "peer_id" && value.size() == 20) - m_peer_id = value; - else if (name == "port") - m_port = htons(atoi(value.c_str())); - - // TorrentPier begin - else if (name == "p") - m_protocol = atoi(value.c_str()); - // TorrentPier end - - break; - case 'u': - if (name == "uploaded") - m_uploaded = atoll(value.c_str()); - // TorrentPier begin - else if (name == "uk") - m_passkey = value; - // TorrentPier end - break; - } -} - -bool Ctracker_input::valid() const -{ - return m_downloaded >= 0 - && (m_event != e_completed || !m_left) - && m_info_hash.size() == 20 - && m_left >= -1 - && m_peer_id.size() == 20 - && m_port >= 0 - && m_uploaded >= 0; -} -bool Ctracker_input::banned() const -{ - if (m_peer_id[7] == '-') - // standard id - switch (m_peer_id[0]) - { - case '-': - switch (m_peer_id[1]) - { - case 'A': // -AZ* > Azureus - return boost::istarts_with(m_peer_id, "-AZ2304") - || boost::istarts_with(m_peer_id, "-AZ2302") - || boost::istarts_with(m_peer_id, "-AZ2300") - || boost::istarts_with(m_peer_id, "-AZ2206") - || boost::istarts_with(m_peer_id, "-AZ2205") - || boost::istarts_with(m_peer_id, "-AZ2204") - || boost::istarts_with(m_peer_id, "-AZ2203") - || boost::istarts_with(m_peer_id, "-AZ2202") - || boost::istarts_with(m_peer_id, "-AZ2201"); - case 'B': // -BC* > BitComet, -BB* > ? - return boost::istarts_with(m_peer_id, "-BB") - || boost::istarts_with(m_peer_id, "-BC0060"); - case 'F': // -FG* > FlashGet - return boost::istarts_with(m_peer_id, "-FG"); - case 'U': // -UT* > uTorrent - return boost::istarts_with(m_peer_id, "-UT11") - || boost::istarts_with(m_peer_id, "-UT11"); - case 'T': // -TS* > TorrentStorm - return boost::istarts_with(m_peer_id, "-TS"); - case 'M': // -MG* > MediaGet - return boost::istarts_with(m_peer_id, "-MG1Cr0") - || boost::istarts_with(m_peer_id, "-MG21"); - default: - return false; - } - //case 'A': // A* > ABC - //case 'M': // M* > Mainline - //case 'S': // S* > Shadow - //case 'T': // T* > BitTornado - //case 'X': // XBT* > XBT - //case 'O': // O* > Opera - default: - return false; - } - else - switch (m_peer_id[0]) - { - case '-': - switch (m_peer_id[1]) - { - //case 'G': // -G3* > G3 - case 'S': // -SZ* > ? - return boost::istarts_with(m_peer_id, "-SZ"); - default: - return false; - } - case 'e': // exbc* > BitComet/BitLord - return boost::istarts_with(m_peer_id, "exbc0L") - || boost::istarts_with(m_peer_id, "exbcL") - || boost::istarts_with(m_peer_id, "exbcLORD") - || boost::istarts_with(m_peer_id, "exbc\08") - || boost::istarts_with(m_peer_id, "exbc\09") - || boost::istarts_with(m_peer_id, "exbc\0:"); - //case 'S': // S57* > Shadow 57 - case 'O': // O* > Opera - return boost::istarts_with(m_peer_id, "O"); - case 'F': // FG* > FlashGet - return boost::istarts_with(m_peer_id, "FG"); - default: - return boost::istarts_with(m_peer_id, "BS") - || boost::istarts_with(m_peer_id, "FUTB") - || boost::istarts_with(m_peer_id, "TO038") - || boost::istarts_with(m_peer_id, "turbo"); - } - return false; -} diff --git a/install/xbt/linux/Tracker/tracker_input.h b/install/xbt/linux/Tracker/tracker_input.h deleted file mode 100644 index dd29b1b52..000000000 --- a/install/xbt/linux/Tracker/tracker_input.h +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#include - -// TorrentPier begin -#include -// TorrentPier end - -class Ctracker_input -{ -public: - void set(const std::string& name, const std::string& value); - bool valid() const; - - // TorrentPier begin - bool banned() const; - Ctracker_input(int family = AF_INET); - // TorrentPier end - - enum t_event - { - e_none, - e_completed, - e_started, - e_stopped, - e_paused, - }; - - typedef std::vector t_info_hashes; - - t_event m_event; - std::string m_info_hash; - t_info_hashes m_info_hashes; - int m_ipa; - std::string m_peer_id; - long long m_downloaded; - long long m_left; - int m_port; - long long m_uploaded; - int m_num_want; - bool m_compact; - - // TorrentPier begin - std::string m_passkey; - bool m_ipv6set; - char m_ipv6bin[16]; - int m_family; - int m_protocol; // 4 for IPv4-only, 6 for IPv6-only - // TorrentPier end -}; diff --git a/install/xbt/linux/Tracker/transaction.cpp b/install/xbt/linux/Tracker/transaction.cpp deleted file mode 100644 index 783fb05fb..000000000 --- a/install/xbt/linux/Tracker/transaction.cpp +++ /dev/null @@ -1,164 +0,0 @@ -#include "stdafx.h" -#include "transaction.h" - -#include -#include -#include -#include -#include - -Ctransaction::Ctransaction(Cserver& server, const Csocket& s): - m_server(server) -{ - m_s = s; -} - -long long Ctransaction::connection_id() const -{ - const int cb_s = 12; - char s[cb_s]; - write_int(8, s, m_server.secret()); - write_int(4, s + 8, m_a.sin_addr.s_addr); - char d[20]; - (Csha1(const_memory_range(s, cb_s))).read(d); - return read_int(8, d); -} - -void Ctransaction::recv() -{ - const int cb_b = 2 << 10; - char b[cb_b]; - while (1) - { - socklen_t cb_a = sizeof(sockaddr_in); - int r = m_s.recvfrom(memory_range(b, cb_b), reinterpret_cast(&m_a), &cb_a); - if (r == SOCKET_ERROR) - { - if (WSAGetLastError() != WSAEWOULDBLOCK) - std::cerr << "recv failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; - return; - } - if (r < uti_size) - return; - switch (read_int(4, b + uti_action, b + r)) - { - case uta_connect: - if (r >= utic_size) - send_connect(const_memory_range(b, r)); - break; - case uta_announce: - if (r >= utia_size) - send_announce(const_memory_range(b, r)); - break; - case uta_scrape: - if (r >= utis_size) - send_scrape(const_memory_range(b, r)); - break; - } - } -} - -void Ctransaction::send_connect(const_memory_range r) -{ - if (!m_server.config().m_anonymous_connect) - return; - if (read_int(8, r + uti_connection_id, r.end) != 0x41727101980ll) - return; - const int cb_d = 2 << 10; - char d[cb_d]; - write_int(4, d + uto_action, uta_connect); - write_int(4, d + uto_transaction_id, read_int(4, r + uti_transaction_id, r.end)); - write_int(8, d + utoc_connection_id, connection_id()); - send(const_memory_range(d, utoc_size)); -} - -void Ctransaction::send_announce(const_memory_range r) -{ - if (read_int(8, r + uti_connection_id, r.end) != connection_id()) - return; - if (!m_server.config().m_anonymous_announce) - { - send_error(r, "access denied"); - return; - } - Ctracker_input ti; - ti.m_downloaded = read_int(8, r + utia_downloaded, r.end); - ti.m_event = static_cast(read_int(4, r + utia_event, r.end)); - ti.m_info_hash.assign(reinterpret_cast(r + utia_info_hash), 20); - ti.m_ipa = read_int(4, r + utia_ipa, r.end) && is_private_ipa(m_a.sin_addr.s_addr) - ? htonl(read_int(4, r + utia_ipa, r.end)) - : m_a.sin_addr.s_addr; - ti.m_left = read_int(8, r + utia_left, r.end); - ti.m_num_want = read_int(4, r + utia_num_want, r.end); - ti.m_peer_id.assign(reinterpret_cast(r + utia_peer_id), 20); - ti.m_port = htons(read_int(2, r + utia_port, r.end)); - ti.m_uploaded = read_int(8, r + utia_uploaded, r.end); - std::string error = m_server.insert_peer(ti, true, NULL); - if (!error.empty()) - { - send_error(r, error); - return; - } - const Cserver::t_file* file = m_server.file(ti.m_info_hash); - if (!file) - return; - const int cb_d = 2 << 10; - char d[cb_d]; - write_int(4, d + uto_action, uta_announce); - write_int(4, d + uto_transaction_id, read_int(4, r + uti_transaction_id, r.end)); - write_int(4, d + utoa_interval, m_server.config().m_announce_interval); - write_int(4, d + utoa_leechers, file->leechers); - write_int(4, d + utoa_seeders, file->seeders); - std::string peers = file->select_peers(ti); - memcpy(d + utoa_size, peers.data(), peers.size()); - send(const_memory_range(d, d + utoa_size + peers.size())); -} - -void Ctransaction::send_scrape(const_memory_range r) -{ - if (read_int(8, r + uti_connection_id, r.end) != connection_id()) - return; - if (!m_server.config().m_anonymous_scrape) - { - send_error(r, "access denied"); - return; - } - const int cb_d = 2 << 10; - char d[cb_d]; - write_int(4, d + uto_action, uta_scrape); - write_int(4, d + uto_transaction_id, read_int(4, r + uti_transaction_id, r.end)); - char* w = d + utos_size; - for (r += utis_size; r + 20 <= r.end && w + 12 <= d + cb_d; r += 20) - { - if (const Cserver::t_file* file = m_server.file(r.sub_range(0, 20).string())) - { - w = write_int(4, w, file->seeders); - w = write_int(4, w, file->completed); - w = write_int(4, w, file->leechers); - } - else - { - w = write_int(4, w, 0); - w = write_int(4, w, 0); - w = write_int(4, w, 0); - } - } - m_server.stats().scraped_udp++; - send(const_memory_range(d, w)); -} - -void Ctransaction::send_error(const_memory_range r, const std::string& msg) -{ - const int cb_d = 2 << 10; - char d[cb_d]; - write_int(4, d + uto_action, uta_error); - write_int(4, d + uto_transaction_id, read_int(4, r + uti_transaction_id, r.end)); - memcpy(d + utoe_size, msg.data(), msg.size()); - send(const_memory_range(d, utoe_size + msg.size())); -} - -void Ctransaction::send(const_memory_range b) -{ - if (m_s.sendto(b, reinterpret_cast(&m_a), sizeof(sockaddr_in)) != b.size()) - std::cerr << "send failed: " << Csocket::error2a(WSAGetLastError()) << std::endl; -} diff --git a/install/xbt/linux/Tracker/transaction.h b/install/xbt/linux/Tracker/transaction.h deleted file mode 100644 index 1a0f2faa1..000000000 --- a/install/xbt/linux/Tracker/transaction.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "server.h" - -class Ctransaction -{ -public: - long long connection_id() const; - void recv(); - void send(const_memory_range); - void send_announce(const_memory_range); - void send_connect(const_memory_range); - void send_scrape(const_memory_range); - void send_error(const_memory_range, const std::string& msg); - Ctransaction(Cserver&, const Csocket&); -private: - Cserver& m_server; - Csocket m_s; - sockaddr_in m_a; -}; diff --git a/install/xbt/linux/Tracker/udp_listen_socket.cpp b/install/xbt/linux/Tracker/udp_listen_socket.cpp deleted file mode 100644 index 13bceea8e..000000000 --- a/install/xbt/linux/Tracker/udp_listen_socket.cpp +++ /dev/null @@ -1,21 +0,0 @@ -#include "stdafx.h" -#include "udp_listen_socket.h" - -#include "transaction.h" - -Cudp_listen_socket::Cudp_listen_socket() -{ - m_server = NULL; -} - -Cudp_listen_socket::Cudp_listen_socket(Cserver* server, const Csocket& s) -{ - m_server = server; - m_s = s; -} - -void Cudp_listen_socket::process_events(int events) -{ - if (events & EPOLLIN) - Ctransaction(*m_server, m_s).recv(); -} diff --git a/install/xbt/linux/Tracker/udp_listen_socket.h b/install/xbt/linux/Tracker/udp_listen_socket.h deleted file mode 100644 index 7e215e097..000000000 --- a/install/xbt/linux/Tracker/udp_listen_socket.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "client.h" - -class Cserver; - -class Cudp_listen_socket: public Cclient -{ -public: - virtual void process_events(int); - Cclient::s; - Cudp_listen_socket(); - Cudp_listen_socket(Cserver*, const Csocket&); -}; diff --git a/install/xbt/linux/Tracker/xbt_tracker b/install/xbt/linux/Tracker/xbt_tracker deleted file mode 100644 index bb16e79da..000000000 Binary files a/install/xbt/linux/Tracker/xbt_tracker and /dev/null differ diff --git a/install/xbt/linux/Tracker/xbt_tracker.pid b/install/xbt/linux/Tracker/xbt_tracker.pid deleted file mode 100644 index 65cbcc0f4..000000000 --- a/install/xbt/linux/Tracker/xbt_tracker.pid +++ /dev/null @@ -1 +0,0 @@ -43033 diff --git a/install/xbt/linux/Tracker/xbtt.sh b/install/xbt/linux/Tracker/xbtt.sh deleted file mode 100644 index 8c2ef8898..000000000 --- a/install/xbt/linux/Tracker/xbtt.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh -# - -# PROVIDE: xbtt -# REQUIRE: NETWORKING mysql - -# Add the following line to /etc/rc.conf to enable XBTT: -# xbtt_enable (bool): Set to "NO" by default. -# Set it to "YES" to enable XBTT. -# xbtt_path (str): Path to dir with xbt_tracker.conf - -. /etc/rc.subr - -name="xbtt" -rcvar=`set_rcvar` -start_precmd="${name}_prestart" - -command="/db/www/xbtt/Tracker/xbt_tracker" - -: ${xbtt_path="/db/www/xbtt/Tracker"} - -xbtt_prestart() -{ - cd ${xbtt_path} -} - -load_rc_config $name -run_rc_command "$1" - - diff --git a/install/xbt/linux/misc/alerts.cpp b/install/xbt/linux/misc/alerts.cpp deleted file mode 100644 index 4a33ed481..000000000 --- a/install/xbt/linux/misc/alerts.cpp +++ /dev/null @@ -1,17 +0,0 @@ -#include "stdafx.h" -#include "alerts.h" - -#include "bt_misc.h" - -int Calert::pre_dump() const -{ - return m_message.size() + m_source.size() + 16; -} - -void Calert::dump(Cstream_writer& w) const -{ - w.write_int(4, m_time); - w.write_int(4, m_level); - w.write_data(m_message); - w.write_data(m_source); -} diff --git a/install/xbt/linux/misc/alerts.h b/install/xbt/linux/misc/alerts.h deleted file mode 100644 index 3c81e8336..000000000 --- a/install/xbt/linux/misc/alerts.h +++ /dev/null @@ -1,75 +0,0 @@ -#pragma once - -#include -#include -#include "stream_writer.h" - -class Calert -{ -public: - enum t_level - { - emerg, - alert, - crit, - error, - warn, - notice, - info, - debug, - }; - - time_t time() const - { - return m_time; - } - - t_level level() const - { - return m_level; - } - - const std::string& message() const - { - return m_message; - } - - void message(const std::string& v) - { - m_message = v; - } - - Calert(t_level level, const std::string& message) - { - m_time = ::time(NULL); - m_level = level; - m_message = message; - } - - Calert(t_level level, const std::string& source, const std::string& message) - { - m_time = ::time(NULL); - m_level = level; - m_message = message; - m_source = source; - } - - int pre_dump() const; - void dump(Cstream_writer&) const; -private: - time_t m_time; - t_level m_level; - std::string m_message; - std::string m_source; -}; - -class Calerts: public std::list -{ -public: - void push_back(const value_type& v) - { - std::list::push_back(v); - while (size() > 250) - erase(begin()); - } -}; diff --git a/install/xbt/linux/misc/bt_misc.cpp b/install/xbt/linux/misc/bt_misc.cpp deleted file mode 100644 index 4c5166fda..000000000 --- a/install/xbt/linux/misc/bt_misc.cpp +++ /dev/null @@ -1,354 +0,0 @@ -#include "stdafx.h" -#include "bt_misc.h" - -#include -#include -#include -#include -#include -#include - -#ifdef WIN32 -#pragma comment(lib, "ws2_32") -#endif - -std::string escape_string(const std::string& v) -{ - std::string w; - w.reserve(v.length()); - BOOST_FOREACH(char i, v) - { - if (isgraph(i & 0xff)) - w += i; - else - { - switch (i) - { - case '\0': - w += "\\0"; - break; - default: - w += "\\x" + hex_encode(2, i); - } - } - } - return w; -} - -std::string generate_random_string(int l) -{ - std::string v; - while (l--) - v += "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"[rand() % 62]; - return v; -} - -std::string get_env(const std::string& v) -{ - const char* p = getenv(v.c_str()); - return p ? p : ""; -} - -static int hex_decode(char v) -{ - if (v >= '0' && v <= '9') - return v - '0'; - if (v >= 'A' && v <= 'F') - return v - 'A' + 10; - if (v >= 'a' && v <= 'f') - return v - 'a' + 10; - return -1; -}; - -std::string hex_decode(const std::string& v) -{ - std::string r; - r.resize(v.length() >> 1); - for (size_t i = 0; i + 2 <= v.length(); i += 2) - { - int a = hex_decode(v[i]); - r[i >> 1] = a << 4 | hex_decode(v[i + 1]); - } - return r; -} - -std::string hex_encode(int l, int v) -{ - std::string r; - r.resize(l); - while (l--) - { - r[l] = "0123456789abcdef"[v & 0xf]; - v >>= 4; - } - return r; -}; - -std::string n(long long v) -{ - char b[21]; -#ifdef WIN32 - sprintf(b, "%I64d", v); -#else - sprintf(b, "%lld", v); -#endif - return b; -} - -std::string hex_encode(const_memory_range v) -{ - std::string r; - r.reserve(v.size() << 1); - for (size_t i = 0; i < v.size(); i++) - r += hex_encode(2, v[i]); - return r; -} - -std::string js_encode(const std::string& v) -{ - std::string r; - BOOST_FOREACH(int i, v) - { - switch (i) - { - case '\"': - case '\'': - case '\\': - r += '\\'; - default: - r += i; - } - } - return r; -} - -std::string uri_decode(const std::string& v) -{ - std::string r; - r.reserve(v.length()); - for (size_t i = 0; i < v.length(); i++) - { - char c = v[i]; - switch (c) - { - case '%': - { - if (i + 1 > v.length()) - return ""; - int l = v[++i]; - r += hex_decode(l) << 4 | hex_decode(v[++i]); - break; - } - case '+': - r += ' '; - break; - default: - r += c; - } - } - return r; -}; - -std::string uri_encode(const std::string& v) -{ - std::string r; - r.reserve(v.length()); - BOOST_FOREACH(char c, v) - { - if (isalpha(c & 0xff) || isdigit(c & 0xff)) - r += c; - else - { - switch (c) - { - case ' ': - r += '+'; - break; - case '-': - case ',': - case '.': - case '@': - case '_': - r += c; - break; - default: - r += "%" + hex_encode(2, c); - } - } - } - return r; -}; - -bool is_private_ipa(int a) -{ - return (ntohl(a) & 0xff000000) == 0x0a000000 - || (ntohl(a) & 0xff000000) == 0x7f000000 - || (ntohl(a) & 0xfff00000) == 0xac100000 - || (ntohl(a) & 0xffff0000) == 0xc0a80000; -} - -std::string b2a(long long v, const char* postfix) -{ - int l; - for (l = 0; v < -9999 || v > 999999; l++) - v >>= 10; - char d[32]; - char* w = d; - if (v > 999) - { - l++; - int b = static_cast((v & 0x3ff) * 100 >> 10); - v >>= 10; - w += sprintf(w, "%d", static_cast(v)); - if (v < 10 && b % 10) - w += sprintf(w, ".%02d", b); - else if (v < 100 && b > 9) - w += sprintf(w, ".%d", b / 10); - } - else - w += sprintf(w, "%d", static_cast(v)); - const char* a[] = {"", " k", " m", " g", " t", " p", " e", " z", " y"}; - w += sprintf(w, "%s", a[l]); - if (postfix) - w += sprintf(w, "%s%s", l ? "" : " ", postfix); - return d; -} - -static std::string peer_id2a(const std::string& name, const std::string& peer_id, int i) -{ - for (size_t j = i; j < peer_id.size(); j++) - { - if (!isalnum(peer_id[j])) - return name + peer_id.substr(i, j - i); - } - return name + peer_id.substr(i); -} - -std::string peer_id2a(const std::string& v) -{ - if (v.length() != 20) - return ""; - if (v[7] == '-') - { - switch (v[0]) - { - case '-': - if (v[1] == 'A' && v[2] == 'Z') - return peer_id2a("Azureus ", v, 3); - if (v[1] == 'B' && v[2] == 'C') - return peer_id2a("BitComet ", v, 3); - if (v[1] == 'U' && v[2] == 'T') - return peer_id2a("uTorrent ", v, 3); - if (v[1] == 'T' && v[2] == 'S') - return peer_id2a("TorrentStorm ", v, 3); - break; - case 'A': - return peer_id2a("ABC ", v, 1); - case 'M': - return peer_id2a("Mainline ", v, 1); - case 'S': - return peer_id2a("Shadow ", v, 1); - case 'T': - return peer_id2a("BitTornado ", v, 1); - case 'X': - if (v[1] == 'B' && v[2] == 'T') - return peer_id2a("XBT Client ", v, 3) + (v.find_first_not_of("0123456789ABCDEFGHIJKLMNOPQRSTUVWYXZabcdefghijklmnopqrstuvwyxz", 8) == std::string::npos ? "" : " (fake)"); - break; - } - } - switch (v[0]) - { - case '-': - if (v[1] == 'G' && v[2] == '3') - return "G3"; - break; - case 'S': - if (v[1] == 5 && v[2] == 7 && v[3] >= 0 && v[3] < 10) - return "Shadow 57" + n(v[3]); - break; - case 'e': - if (v[1] == 'x' && v[2] == 'b' && v[3] == 'c' && v[4] >= 0 && v[4] < 10 && v[5] >= 0 && v[5] < 100) - return "BitComet " + n(v[4]) + '.' + n(v[5] / 10) + n(v[5] % 10); - } - return "Unknown"; -} - -std::string duration2a(float v) -{ - char d[32]; - if (v > 31557600) - sprintf(d, "%.1f years", v / 31557600); - else if (v > 2629800) - sprintf(d, "%.1f months", v / 2629800); - else if (v > 604800) - sprintf(d, "%.1f weeks", v / 604800); - else if (v > 86400) - sprintf(d, "%.1f days", v / 86400); - else if (v > 3600) - sprintf(d, "%.1f hours", v / 3600); - else if (v > 60) - sprintf(d, "%.1f minutes", v / 60); - else - sprintf(d, "%.1f seconds", v); - return d; -} - -std::string time2a(time_t v) -{ - const tm* date = localtime(&v); - if (!date) - return ""; - char b[20]; - sprintf(b, "%04d-%02d-%02d %02d:%02d:%02d", date->tm_year + 1900, date->tm_mon + 1, date->tm_mday, date->tm_hour, date->tm_min, date->tm_sec); - return b; -} - -int merkle_tree_size(int v) -{ - int r = 0; - while (v > 1) - { - r += v++; - v >>= 1; - } - if (v == 1) - r++; - return r; -} - -std::string backward_slashes(std::string v) -{ - std::replace(v.begin(), v.end(), '/', '\\'); - return v; -} - -std::string forward_slashes(std::string v) -{ - std::replace(v.begin(), v.end(), '\\', '/'); - return v; -} - -std::string native_slashes(const std::string& v) -{ -#ifdef WIN32 - return backward_slashes(v); -#else - return forward_slashes(v); -#endif -} - -int hms2i(int h, int m, int s) -{ - return 60 * (h + 60 * m) + s; -} - -int xbt_atoi(const std::string& a) -{ - int i = atoi(a.c_str()); - return n(i) == a ? i : 0; -} - -std::string xbt_version2a(int v) -{ - return n(v / 100) + "." + n(v / 10 % 10) + "." + n(v % 10); -} diff --git a/install/xbt/linux/misc/bt_misc.h b/install/xbt/linux/misc/bt_misc.h deleted file mode 100644 index 79907adda..000000000 --- a/install/xbt/linux/misc/bt_misc.h +++ /dev/null @@ -1,96 +0,0 @@ -#pragma once - -#include -#include - -std::string b2a(long long v, const char* postfix = NULL); -std::string backward_slashes(std::string); -std::string duration2a(float); -std::string escape_string(const std::string&); -std::string forward_slashes(std::string); -std::string generate_random_string(int); -std::string get_env(const std::string&); -int hms2i(int h, int m, int s); -bool is_private_ipa(int a); -int merkle_tree_size(int v); -std::string n(long long); -std::string native_slashes(const std::string&); -std::string hex_decode(const std::string&); -std::string hex_encode(int l, int v); -std::string hex_encode(const_memory_range); -std::string js_encode(const std::string&); -std::string peer_id2a(const std::string&); -std::string time2a(time_t); -std::string uri_decode(const std::string&); -std::string uri_encode(const std::string&); -int xbt_atoi(const std::string&); -std::string xbt_version2a(int); - -inline long long htonll(long long v) -{ - const unsigned char* a = reinterpret_cast(&v); - long long b = a[0] << 24 | a[1] << 16 | a[2] << 8 | a[3]; - return b << 32 | static_cast(a[4]) << 24 | a[5] << 16 | a[6] << 8 | a[7]; -} - -inline long long ntohll(long long v) -{ - return htonll(v); -} - -enum -{ - hs_name_size = 0, - hs_name = 1, - hs_reserved = 20, - hs_info_hash = 28, - hs_size = 48, -}; - -enum -{ - uta_connect, - uta_announce, - uta_scrape, - uta_error, -}; - -enum -{ - uti_connection_id = 0, - uti_action = 8, - uti_transaction_id = 12, - uti_size = 16, - - utic_size = 16, - - utia_info_hash = 16, - utia_peer_id = 36, - utia_downloaded = 56, - utia_left = 64, - utia_uploaded = 72, - utia_event = 80, - utia_ipa = 84, - utia_key = 88, - utia_num_want = 92, - utia_port = 96, - utia_size = 98, - - utis_size = 16, - - uto_action = 0, - uto_transaction_id = 4, - uto_size = 8, - - utoc_connection_id = 8, - utoc_size = 16, - - utoa_interval = 8, - utoa_leechers = 12, - utoa_seeders = 16, - utoa_size = 20, - - utos_size = 8, - - utoe_size = 8, -}; diff --git a/install/xbt/linux/misc/bt_strings.h b/install/xbt/linux/misc/bt_strings.h deleted file mode 100644 index f8ed4c986..000000000 --- a/install/xbt/linux/misc/bt_strings.h +++ /dev/null @@ -1,114 +0,0 @@ -#pragma once - -enum -{ - bti_choke , - bti_unchoke, - bti_interested, - bti_uninterested, - bti_have, - bti_bitfield, - bti_request, - bti_piece, - bti_cancel, - - bti_get_info, - bti_info, - bti_get_peers, - bti_peers, - - bti_extended = 20, - - bti_bvalue = 0x40, -}; - -enum -{ - bti_extended_handshake, - bti_extended_ut_pex, -}; - -enum -{ - bti_none, - bti_completed, - bti_started, - bti_stopped, -}; - -const std::string bts_action = "action"; -const std::string bts_admin_port = "admin port"; -const std::string bts_admin_user = "admin user"; -const std::string bts_admin_pass = "admin pass"; -const std::string bts_announce = "announce"; -const std::string bts_announce_list = "announce-list"; -const std::string bts_banned_client = "access denied, banned client"; -const std::string bts_can_not_leech = "access denied, leeching forbidden, you are only allowed to seed"; -const std::string bts_close_torrent = "close torrent"; -const std::string bts_complete = "complete"; -const std::string bts_complete_total = "complete total"; -const std::string bts_completed_at = "completed at"; -const std::string bts_completes_dir = "completes dir"; -const std::string bts_down_rate = "down rate"; -const std::string bts_downloaded = "downloaded"; -const std::string bts_erase_torrent = "erase torrent"; -const std::string bts_events = "events"; -const std::string bts_failure_reason = "failure reason"; -const std::string bts_files = "files"; -const std::string bts_flags = "flags"; -const std::string bts_get_options = "get options"; -const std::string bts_get_status = "get status"; -const std::string bts_hash = "hash"; -const std::string bts_incomplete = "incomplete"; -const std::string bts_incomplete_total = "incomplete total"; -const std::string bts_incompletes_dir = "incompletes dir"; -const std::string bts_info = "info"; -const std::string bts_interval = "interval"; -const std::string bts_ipa = "ip"; -const std::string bts_left = "left"; -const std::string bts_length = "length"; -const std::string bts_login = "login"; -const std::string bts_merkle_hash = "merkle hash"; -const std::string bts_message = "message"; -const std::string bts_min_interval = "min interval"; -const std::string bts_min_request_interval = "min_request_interval"; -const std::string bts_name = "name"; -const std::string bts_open_torrent = "open torrent"; -const std::string bts_pass = "pass"; -const std::string bts_path = "path"; -const std::string bts_peer_id = "peer id"; -const std::string bts_peer_limit = "peer limit"; -const std::string bts_peer_port = "peer port"; -const std::string bts_peers = "peers"; -const std::string bts_peers_limit_reached = "access denied, peers limit reached"; -const std::string bts_piece_length = "piece length"; -const std::string bts_pieces = "pieces"; -const std::string bts_private = "private"; -const std::string bts_port = "port"; -const std::string bts_priority = "priority"; -const std::string bts_seeding_ratio = "seeding ratio"; -const std::string bts_set_options = "set options"; -const std::string bts_set_priority = "set priority"; -const std::string bts_set_state = "set state"; -const std::string bts_size = "size"; -const std::string bts_started_at = "started at"; -const std::string bts_state = "state"; -const std::string bts_time = "time"; -const std::string bts_torrent = "torrent"; -const std::string bts_torrent_limit = "torrent limit"; -const std::string bts_torrents_dir = "torrents dir"; -const std::string bts_torrents_limit_reached = "access denied, torrents limit reached"; -const std::string bts_total_downloaded = "total downloaded"; -const std::string bts_total_uploaded = "total uploaded"; -const std::string bts_tracker_port = "tracker port"; -const std::string bts_unregistered_ipa = "unregistered IP address"; -const std::string bts_unregistered_torrent = "unregistered torrent"; -const std::string bts_unregistered_torrent_pass = "unregistered torrent pass"; -const std::string bts_unsupported_tracker_protocol = "unsupported tracker protocol, please upgrade your client"; -const std::string bts_up_rate = "up rate"; -const std::string bts_upload_rate = "upload rate"; -const std::string bts_upload_slots = "upload slots"; -const std::string bts_user_agent = "user agent"; -const std::string bts_version = "version"; -const std::string bts_wait_time = "access denied, wait time in effect"; -const std::string bts_disabled = "access denied, account disabled"; \ No newline at end of file diff --git a/install/xbt/linux/misc/bt_torrent.cpp b/install/xbt/linux/misc/bt_torrent.cpp deleted file mode 100644 index 8adaac78b..000000000 --- a/install/xbt/linux/misc/bt_torrent.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "stdafx.h" -#include "bt_torrent.h" - -#include "bt_strings.h" - -Cbt_torrent::Cbt_torrent() -{ -} - -Cbt_torrent::Cbt_torrent(const Cbvalue& v) -{ - write(v); -} - -int Cbt_torrent::write(const Cbvalue& v) -{ - m_announce = v[bts_announce].s(); - m_announces.clear(); - const Cbvalue::t_list& announces = v[bts_announce_list].l(); - for (Cbvalue::t_list::const_iterator i = announces.begin(); i != announces.end(); i++) - { - for (Cbvalue::t_list::const_iterator j = i->l().begin(); j != i->l().end(); j++) - m_announces.push_back(j->s()); - } - return write_info(v[bts_info]); -} - -int Cbt_torrent::write_info(const Cbvalue& v) -{ - m_files.clear(); - const Cbvalue::t_list& files = v[bts_files].l(); - for (Cbvalue::t_list::const_iterator i = files.begin(); i != files.end(); i++) - { - std::string name; - long long size = (*i)[bts_length].i(); - { - const Cbvalue::t_list& path = (*i)[bts_path].l(); - for (Cbvalue::t_list::const_iterator i = path.begin(); i != path.end(); i++) - { - if (i->s().empty() || i->s()[0] == '.' || i->s().find_first_of("\"*/:<>?\\|") != std::string::npos) - return 1; - name += '/' + i->s(); - } - } - if (name.empty()) - return 1; - m_files.push_back(Cfile(name, size)); - } - if (m_files.empty()) - m_files.push_back(Cfile("", v[bts_length].i())); - m_name = v[bts_name].s(); - m_piece_size = v[bts_piece_length].i(); - return 0; -} - -long long Cbt_torrent::size() const -{ - long long r = 0; - for (t_files::const_iterator i = m_files.begin(); i != m_files.end(); i++) - r += i->size(); - return r; -} - -bool Cbt_torrent::valid() const -{ - for (t_files::const_iterator i = m_files.begin(); i != m_files.end(); i++) - { - if (i->size() < 0) - return false; - } - return !files().empty() - && !name().empty() - && name()[0] != '.' - && name().find_first_of("\"*/:<>?\\|") == std::string::npos - && piece_size() >= 16 << 10 - && piece_size() <= 4 << 20; -} diff --git a/install/xbt/linux/misc/bt_torrent.h b/install/xbt/linux/misc/bt_torrent.h deleted file mode 100644 index 7540d782b..000000000 --- a/install/xbt/linux/misc/bt_torrent.h +++ /dev/null @@ -1,75 +0,0 @@ -#pragma once - -#include "bvalue.h" - -class Cbt_torrent -{ -public: - class Cfile - { - public: - const std::string& name() const - { - return m_name; - } - - long long size() const - { - return m_size; - } - - Cfile() - { - } - - Cfile(const std::string& name, long long size) - { - m_name = name; - m_size = size; - } - private: - std::string m_name; - long long m_size; - }; - - typedef std::vector t_announces; - typedef std::vector t_files; - - long long size() const; - bool valid() const; - int write(const Cbvalue&); - int write_info(const Cbvalue&); - Cbt_torrent(); - Cbt_torrent(const Cbvalue&); - - const std::string& announce() const - { - return m_announce; - } - - const t_announces& announces() const - { - return m_announces; - } - - const t_files& files() const - { - return m_files; - } - - const std::string& name() const - { - return m_name; - } - - int piece_size() const - { - return m_piece_size; - } -private: - std::string m_announce; - t_announces m_announces; - t_files m_files; - std::string m_name; - int m_piece_size; -}; diff --git a/install/xbt/linux/misc/bt_tracker_account.cpp b/install/xbt/linux/misc/bt_tracker_account.cpp deleted file mode 100644 index 9f3458af9..000000000 --- a/install/xbt/linux/misc/bt_tracker_account.cpp +++ /dev/null @@ -1,68 +0,0 @@ -#include "stdafx.h" -#include "xbt/virtual_binary.h" -#include "bt_tracker_account.h" - -#include "stream_reader.h" - -Cbt_tracker_account::Cbt_tracker_account() -{ -} - -Cbt_tracker_account::Cbt_tracker_account(const std::string& tracker, const std::string& user, const std::string& pass) -{ - m_tracker = tracker; - m_user = user; - m_pass = pass; -} - -int Cbt_tracker_account::pre_dump() const -{ - return tracker().size() + user().size() + pass().size() + 12; -} - -void Cbt_tracker_account::dump(Cstream_writer& w) const -{ - w.write_data(tracker()); - w.write_data(user()); - w.write_data(pass()); -} - -Cvirtual_binary Cbt_tracker_accounts::dump() const -{ - int cb_d = 4; - for (const_iterator i = begin(); i != end(); i++) - cb_d += i->pre_dump(); - Cvirtual_binary d; - Cstream_writer w(d.write_start(cb_d)); - w.write_int(4, size()); - for (const_iterator i = begin(); i != end(); i++) - i->dump(w); - assert(w.w() == d.end()); - return d; - -} - -const Cbt_tracker_account* Cbt_tracker_accounts::find(const std::string& v) const -{ - for (const_iterator i = begin(); i != end(); i++) - { - if (i->tracker() == v) - return &*i; - } - return NULL; -} - -void Cbt_tracker_accounts::load(const Cvirtual_binary& s) -{ - clear(); - if (s.size() < 4) - return; - Cstream_reader r(s); - for (int count = r.read_int(4); count--; ) - { - std::string tracker = r.read_string(); - std::string name = r.read_string(); - std::string pass = r.read_string(); - push_back(Cbt_tracker_account(tracker, name, pass)); - } -} diff --git a/install/xbt/linux/misc/bt_tracker_account.h b/install/xbt/linux/misc/bt_tracker_account.h deleted file mode 100644 index 34ee73247..000000000 --- a/install/xbt/linux/misc/bt_tracker_account.h +++ /dev/null @@ -1,39 +0,0 @@ -#pragma once - -#include - -class Cbt_tracker_account -{ -public: - int pre_dump() const; - void dump(Cstream_writer&) const; - Cbt_tracker_account(); - Cbt_tracker_account(const std::string& tracker, const std::string& user, const std::string& pass); - - const std::string& tracker() const - { - return m_tracker; - } - - const std::string& user() const - { - return m_user; - } - - const std::string& pass() const - { - return m_pass; - } -private: - std::string m_tracker; - std::string m_user; - std::string m_pass; -}; - -class Cbt_tracker_accounts: public std::list -{ -public: - Cvirtual_binary dump() const; - const Cbt_tracker_account* find(const std::string&) const; - void load(const Cvirtual_binary&); -}; diff --git a/install/xbt/linux/misc/bt_tracker_url.cpp b/install/xbt/linux/misc/bt_tracker_url.cpp deleted file mode 100644 index c31ed9711..000000000 --- a/install/xbt/linux/misc/bt_tracker_url.cpp +++ /dev/null @@ -1,82 +0,0 @@ -#include "stdafx.h" -#include "bt_tracker_url.h" - -#include - -Cbt_tracker_url::Cbt_tracker_url() -{ -} - -Cbt_tracker_url::Cbt_tracker_url(const std::string& v) -{ - write(v); -} - -void Cbt_tracker_url::clear() -{ - m_protocol = tp_unknown; - m_host.erase(); - m_port = 0; - m_path.erase(); -} - -bool Cbt_tracker_url::valid() const -{ - switch (m_protocol) - { - case tp_http: - if (m_path.empty() || m_path[0] != '/') - return false; - case tp_udp: - return !m_host.empty() - && m_port >= 0 && m_port < 0x10000; - } - return false; -} - -void Cbt_tracker_url::write(const std::string& v) -{ - clear(); - size_t a; - int protocol; - int port; - if (boost::istarts_with(v, "http://")) - { - a = 7; - protocol = tp_http; - port = 80; - } - else if (boost::istarts_with(v, "udp://")) - { - a = 6; - protocol = tp_udp; - port = 2710; - } - else - return; - size_t b = v.find_first_of("/:", a); - std::string host; - if (b == std::string::npos) - host = v.substr(a); - else - { - host = v.substr(a, b - a); - if (v[b] == '/') - m_path = v.substr(b); - else - { - b++; - a = v.find('/', b); - if (a == std::string::npos) - port = atoi(v.substr(b).c_str()); - else - { - port = atoi(v.substr(b, a - b).c_str()); - m_path = v.substr(a); - } - } - } - m_protocol = protocol; - m_host = host; - m_port = port; -} diff --git a/install/xbt/linux/misc/bt_tracker_url.h b/install/xbt/linux/misc/bt_tracker_url.h deleted file mode 100644 index a6ad3c905..000000000 --- a/install/xbt/linux/misc/bt_tracker_url.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#include - -class Cbt_tracker_url -{ -public: - enum - { - tp_http, - tp_udp, - tp_unknown - }; - - void clear(); - bool valid() const; - void write(const std::string&); - Cbt_tracker_url(const std::string&); - Cbt_tracker_url(); - - int m_protocol; - std::string m_host; - int m_port; - std::string m_path; -}; diff --git a/install/xbt/linux/misc/bvalue.cpp b/install/xbt/linux/misc/bvalue.cpp deleted file mode 100644 index 6daa9f371..000000000 --- a/install/xbt/linux/misc/bvalue.cpp +++ /dev/null @@ -1,370 +0,0 @@ -#include "stdafx.h" -#include "bvalue.h" - -#include -#include -#include "bt_misc.h" - -Cbvalue::Cbvalue(long long v) -{ - m_value_type = vt_int; - m_int = v; -} - -Cbvalue::Cbvalue(t_value_type t) -{ - switch (m_value_type = t) - { - case vt_int: - break; - case vt_string: - m_string = new std::string; - break; - case vt_list: - m_list = new t_list; - break; - case vt_dictionary: - m_map = new t_map; - break; - default: - assert(false); - } -} - -Cbvalue::Cbvalue(const std::string& v) -{ - m_value_type = vt_string; - m_string = new std::string(v); -} - -Cbvalue::Cbvalue(const Cbvalue& v) -{ - switch (m_value_type = v.m_value_type) - { - case vt_int: - m_int = v.m_int; - break; - case vt_string: - m_string = new std::string(*v.m_string); - break; - case vt_list: - m_list = new t_list(*v.m_list); - break; - case vt_dictionary: - m_map = new t_map(*v.m_map); - break; - default: - assert(false); - } -} - -Cbvalue::Cbvalue(const_memory_range s) -{ - m_value_type = vt_int; - if (write(s)) - clear(); -} - -Cbvalue::~Cbvalue() -{ - clear(); -} - -const Cbvalue& Cbvalue::operator=(const Cbvalue& v) -{ - clear(); - m_value_type = v.m_value_type; - switch (v.m_value_type) - { - case vt_int: - m_int = v.m_int; - break; - case vt_string: - m_string = new std::string(*v.m_string); - break; - case vt_list: - m_list = new t_list(*v.m_list); - break; - case vt_dictionary: - m_map = new t_map(*v.m_map); - break; - default: - assert(false); - } - return *this; -} - -int Cbvalue::write(const_memory_range s) -{ - return write(reinterpret_cast(s.begin), s.size()); -} - -int Cbvalue::write(const char* s, int cb_s) -{ - return write(s, s + cb_s); -} - -int Cbvalue::write(const char*& s, const char* s_end) -{ - clear(); - if (s >= s_end) - return 1; - switch (*s++) - { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - { - const char* a = s - 1; - while (s < s_end && *s != ':') - s++; - if (s++ >= s_end) - return 1; - int l = atoi(a); - if (s + l > s_end) - return 1; - m_value_type = vt_string; - m_string = new std::string(s, l); - s += l; - return 0; - } - case 'd': - { - m_value_type = vt_dictionary; - m_map = new t_map; - while (s < s_end && *s != 'e') - { - Cbvalue v; - Cbvalue w; - if (v.write(s, s_end) || v.m_value_type != vt_string) - return 1; - if (w.write(s, s_end)) - return 1; - (*m_map)[*v.m_string] = w; - } - if (s++ >= s_end) - return 1; - return 0; - } - break; - case 'i': - { - const char* a = s; - while (s < s_end && *s != 'e') - s++; - if (s++ >= s_end) - return 1; - m_value_type = vt_int; - m_int = atoll(a); - return 0; - } - case 'l': - { - m_value_type = vt_list; - m_list = new t_list; - while (s < s_end && *s != 'e') - { - Cbvalue v; - if (v.write(s, s_end)) - return 1; - m_list->push_back(v); - } - if (s++ >= s_end) - return 1; - return 0; - } - } - return 1; -} - -void Cbvalue::clear() -{ - switch (m_value_type) - { - case vt_int: - break; - case vt_string: - delete m_string; - break; - case vt_list: - delete m_list; - break; - case vt_dictionary: - delete m_map; - break; - default: - assert(false); - } - m_value_type = vt_int; -} - -const Cbvalue::t_map& Cbvalue::d() const -{ - static t_map z; - return m_value_type == vt_dictionary ? *m_map : z; -} - -bool Cbvalue::d_has(const std::string& v) const -{ - return m_value_type == vt_dictionary && m_map->find(v) != m_map->end(); -} - -const Cbvalue& Cbvalue::d(const std::string& v) const -{ - if (m_value_type == vt_dictionary) - { - t_map::const_iterator i = m_map->find(v); - if (i != m_map->end()) - return i->second; - } - static Cbvalue z; - return z; -} - -const Cbvalue& Cbvalue::operator[](const std::string& v) const -{ - return d(v); -} - -long long Cbvalue::i() const -{ - return m_value_type == vt_int ? m_int : 0; -} - -const Cbvalue::t_list& Cbvalue::l() const -{ - static t_list z; - return m_value_type == vt_list ? *m_list : z; -} - -const std::string& Cbvalue::s() const -{ - static std::string z; - return m_value_type == vt_string ? *m_string : z; -} - -Cbvalue& Cbvalue::d(const std::string& v, const Cbvalue& w) -{ - if (m_value_type != vt_dictionary) - { - clear(); - m_value_type = vt_dictionary; - m_map = new t_map; - } - (*m_map)[v] = w; - return *this; -} - -Cbvalue& Cbvalue::l(const Cbvalue& v) -{ - if (m_value_type != vt_list) - { - clear(); - m_value_type = vt_list; - m_list = new t_list; - } - (*m_list).push_back(v); - return *this; -} - -int Cbvalue::pre_read() const -{ - switch (m_value_type) - { - case vt_int: - return n(m_int).size() + 2; - case vt_string: - return n(m_string->size()).size() + m_string->size() + 1; - case vt_list: - { - int v = 2; - BOOST_FOREACH(t_list::const_reference i, *m_list) - v += i.pre_read(); - return v; - } - case vt_dictionary: - { - int v = 2; - BOOST_FOREACH(t_map::const_reference i, *m_map) - v += n(i.first.size()).size() + i.first.size() + i.second.pre_read() + 1; - return v; - } - } - assert(false); - return 0; -} - -Cvirtual_binary Cbvalue::read() const -{ - Cvirtual_binary d; - int cb_d = read(d.write_start(pre_read())); - assert(cb_d == d.size()); - return d; -} - -int Cbvalue::read(void* d) const -{ - return read(reinterpret_cast(d)); -} - -int Cbvalue::read(char* d) const -{ - char* w = d; - switch (m_value_type) - { - case vt_int: -#ifdef WIN32 - sprintf(d, "i%I64d", m_int); -#else - sprintf(d, "i%lld", m_int); -#endif - w += strlen(d); - *w++ = 'e'; - return w - d; - case vt_string: -#ifdef WIN32 - sprintf(w, "%d:", m_string->size()); -#else - sprintf(w, "%zu:", m_string->size()); -#endif - w += n(m_string->size()).size() + 1; - memcpy(w, m_string->data(), m_string->size()); - w += m_string->size(); - return w - d; - case vt_list: - { - *w++ = 'l'; - for (t_list::const_iterator i = m_list->begin(); i != m_list->end(); i++) - w += i->read(w); - *w++ = 'e'; - return w - d; - } - case vt_dictionary: - { - *w++ = 'd'; - for (t_map::const_iterator i = m_map->begin(); i != m_map->end(); i++) - { -#ifdef WIN32 - sprintf(w, "%d:", i->first.size()); -#else - sprintf(w, "%zu:", i->first.size()); -#endif - w += n(i->first.size()).size() + 1; - memcpy(w, i->first.data(), i->first.size()); - w += i->first.size(); - w += i->second.read(w); - } - *w++ = 'e'; - return w - d; - } - } - assert(false); - return 0; -} diff --git a/install/xbt/linux/misc/bvalue.h b/install/xbt/linux/misc/bvalue.h deleted file mode 100644 index 5a031617c..000000000 --- a/install/xbt/linux/misc/bvalue.h +++ /dev/null @@ -1,58 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -class Cbvalue -{ -public: - enum t_value_type - { - vt_int, - vt_string, - vt_list, - vt_dictionary, - }; - - typedef std::map t_map; - typedef std::vector t_list; - - void clear(); - const t_map& d() const; - const t_list& l() const; - long long i() const; - const std::string& s() const; - bool d_has(const std::string&) const; - Cbvalue& d(const std::string& v, const Cbvalue& w); - Cbvalue& l(const Cbvalue& v); - int pre_read() const; - int read(char* d) const; - int read(void* d) const; - Cvirtual_binary read() const; - int write(const char* s, int cb_s); - int write(const_memory_range); - Cbvalue(long long v = 0); - Cbvalue(t_value_type t); - Cbvalue(const std::string& v); - Cbvalue(const Cbvalue&); - Cbvalue(const_memory_range); - const Cbvalue& operator=(const Cbvalue&); - const Cbvalue& operator[](const std::string&) const; - ~Cbvalue(); -private: - const Cbvalue& d(const std::string&) const; - - t_value_type m_value_type; - - union - { - long long m_int; - std::string* m_string; - t_list* m_list; - t_map* m_map; - }; - - int write(const char*& s, const char* s_end); -}; diff --git a/install/xbt/linux/misc/config_base.h b/install/xbt/linux/misc/config_base.h deleted file mode 100644 index 18a8bd63b..000000000 --- a/install/xbt/linux/misc/config_base.h +++ /dev/null @@ -1,108 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include - -class Cconfig_base -{ -public: - template - struct t_attribute - { - const char* key; - T* value; - T default_value; - }; - - template - class t_attributes: public std::map > - { - }; - - virtual int set(const std::string& name, const std::string& value) - { - t_attributes::iterator i = m_attributes_string.find(name); - if (i != m_attributes_string.end()) - *i->second.value = value; - else - return set(name, atoi(value.c_str())); - return 0; - } - - virtual int set(const std::string& name, int value) - { - t_attributes::iterator i = m_attributes_int.find(name); - if (i != m_attributes_int.end()) - *i->second.value = value; - else - return set(name, static_cast(value)); - return 0; - } - - virtual int set(const std::string& name, bool value) - { - t_attributes::iterator i = m_attributes_bool.find(name); - if (i != m_attributes_bool.end()) - *i->second.value = value; - else - return 1; - return 0; - } - - std::istream& load(std::istream& is) - { - for (std::string s; getline(is, s); ) - { - size_t i = s.find('='); - if (i != std::string::npos) - set(boost::trim_copy(s.substr(0, i)), boost::trim_copy(s.substr(i + 1))); - } - return is; - } - - int load(const std::string& file) - { - std::ifstream is(file.c_str()); - if (!is) - return 1; - load(is); - return !is.eof(); - } - - std::ostream& save(std::ostream& os) const - { - save_map(os, m_attributes_bool); - save_map(os, m_attributes_int); - save_map(os, m_attributes_string); - return os; - } - -protected: - t_attributes m_attributes_bool; - t_attributes m_attributes_int; - t_attributes m_attributes_string; - - template - void fill_map(t_attribute* attributes, const t_attributes* s, t_attributes& d) - { - for (t_attribute* i = attributes; i->key; i++) - { - *i->value = s ? *s->find(i->key)->second.value : i->default_value; - d[i->key] = *i; - } - } - - template - void save_map(std::ostream& os, const T& v) const - { - for (typename T::const_iterator i = v.begin(); i != v.end(); i++) - { - if (*i->second.value == i->second.default_value) - os << "# "; - os << i->first << " = " << *i->second.value << std::endl; - } - } -}; diff --git a/install/xbt/linux/misc/const_memory_range.h b/install/xbt/linux/misc/const_memory_range.h deleted file mode 100644 index 70fa7abf2..000000000 --- a/install/xbt/linux/misc/const_memory_range.h +++ /dev/null @@ -1,252 +0,0 @@ -#pragma once - -#include -#include -#include - -template -class memory_range_base -{ -public: - memory_range_base() - { - begin = NULL; - end = NULL; - } - - template - memory_range_base(const memory_range_base& v) - { - assign(v.begin, v.end); - } - - memory_range_base(void* begin_, void* end_) - { - assign(begin_, end_); - } - - memory_range_base(void* begin_, size_t size) - { - assign(begin_, size); - } - - template - memory_range_base(boost::array& v) - { - assign(&v.front(), v.size()); - } - - template - memory_range_base(boost::array& v) - { - assign(&v.front(), v.size()); - } - - memory_range_base(std::vector& v) - { - assign(&v.front(), v.size()); - } - - memory_range_base(std::vector& v) - { - assign(&v.front(), v.size()); - } - - memory_range_base assign(void* begin_, void* end_) - { - begin = reinterpret_cast(begin_); - end = reinterpret_cast(end_); - return *this; - } - - memory_range_base assign(void* begin_, size_t size) - { - begin = reinterpret_cast(begin_); - end = begin + size; - return *this; - } - - void clear() - { - begin = end = NULL; - } - - bool empty() const - { - return begin == end; - } - - size_t size() const - { - return end - begin; - } - - std::string string() const - { - return std::string(reinterpret_cast(begin), size()); - } - - memory_range_base sub_range(size_t o, size_t s) - { - return memory_range_base(begin + o, s); - } - - operator T() const - { - return begin; - } - - memory_range_base operator++(int) - { - memory_range_base t = *this; - begin++; - return t; - } - - memory_range_base operator+=(size_t v) - { - begin += v; - return *this; - } - - T begin; - T end; -}; - -typedef memory_range_base memory_range; - -template -class const_memory_range_base -{ -public: - const_memory_range_base() - { - begin = NULL; - end = NULL; - } - - template - const_memory_range_base(const const_memory_range_base& v) - { - assign(v.begin, v.end); - } - - template - const_memory_range_base(const memory_range_base& v) - { - assign(v.begin, v.end); - } - - const_memory_range_base(const void* begin_, const void* end_) - { - assign(begin_, end_); - } - - const_memory_range_base(const void* begin_, size_t size) - { - assign(begin_, size); - } - - const_memory_range_base(const std::string& v) - { - assign(v.data(), v.size()); - } - - template - const_memory_range_base(const boost::array& v) - { - assign(&v.front(), v.size()); - } - - template - const_memory_range_base(const boost::array& v) - { - assign(&v.front(), v.size()); - } - - const_memory_range_base(const std::vector& v) - { - assign(&v.front(), v.size()); - } - - const_memory_range_base(const std::vector& v) - { - assign(&v.front(), v.size()); - } - - const_memory_range_base assign(const void* begin_, const void* end_) - { - begin = reinterpret_cast(begin_); - end = reinterpret_cast(end_); - return *this; - } - - const_memory_range_base assign(const void* begin_, size_t size) - { - begin = reinterpret_cast(begin_); - end = begin + size; - return *this; - } - - void clear() - { - begin = end = NULL; - } - - bool empty() const - { - return begin == end; - } - - template - const_memory_range_base find(U v) const - { - const_memory_range_base t = *this; - while (!t.empty() && *t != v) - t++; - return t; - } - - long long i() const - { - return atoll(reinterpret_cast(begin)); - } - - size_t size() const - { - return end - begin; - } - - std::string string() const - { - return std::string(reinterpret_cast(begin), size()); - } - - const_memory_range_base sub_range(size_t o, size_t s) - { - return const_memory_range_base(begin + o, s); - } - - operator T() const - { - return begin; - } - - const_memory_range_base operator++(int) - { - const_memory_range_base t = *this; - begin++; - return t; - } - - const_memory_range_base operator+=(size_t v) - { - begin += v; - return *this; - } - - T begin; - T end; -}; - -typedef const_memory_range_base const_memory_range; diff --git a/install/xbt/linux/misc/find_ptr.h b/install/xbt/linux/misc/find_ptr.h deleted file mode 100644 index 231a447d1..000000000 --- a/install/xbt/linux/misc/find_ptr.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -template -typename T::mapped_type* find_ptr(T& c, U v) -{ - typename T::iterator i = c.find(v); - return i == c.end() ? NULL : &i->second; -} - -template -const typename T::mapped_type* find_ptr(const T& c, U v) -{ - typename T::const_iterator i = c.find(v); - return i == c.end() ? NULL : &i->second; -} diff --git a/install/xbt/linux/misc/sha1.cpp b/install/xbt/linux/misc/sha1.cpp deleted file mode 100644 index ff90e66b8..000000000 --- a/install/xbt/linux/misc/sha1.cpp +++ /dev/null @@ -1,419 +0,0 @@ -/* - * sha1.c - * - * Description: - * This file implements the Secure Hashing Algorithm 1 as - * defined in FIPS PUB 180-1 published April 17, 1995. - * - * The SHA-1, produces a 160-bit message digest for a given - * data stream. It should take about 2**n steps to find a - * message with the same digest as a given message and - * 2**(n/2) to find any two messages with the same digest, - * when n is the digest size in bits. Therefore, this - * algorithm can serve as a means of providing a - * "fingerprint" for a message. - * - * Portability Issues: - * SHA-1 is defined in terms of 32-bit "words". This code - * uses (included via "sha1.h" to define 32 and 8 - * bit unsigned integer types. If your C compiler does not - * support 32 bit unsigned integers, this code is not - * appropriate. - * - * Caveats: - * SHA-1 is designed to work with messages less than 2^64 bits - * long. Although SHA-1 allows a message digest to be generated - * for messages of any number of bits less than 2^64, this - * implementation only works with messages with a length that is - * a multiple of the size of an 8-bit character. - * - */ - -#include "stdafx.h" -#include "sha1.h" - -/* - * Define the SHA1 circular left shift macro - */ -#define SHA1CircularShift(bits,word) \ - (((word) << (bits)) | ((word) >> (32-(bits)))) - -/* Local Function Prototyptes */ -void SHA1PadMessage(SHA1Context *); -void SHA1ProcessMessageBlock(SHA1Context *); - -/* - * SHA1Reset - * - * Description: - * This function will initialize the SHA1Context in preparation - * for computing a new SHA1 message digest. - * - * Parameters: - * context: [in/out] - * The context to reset. - * - * Returns: - * sha Error Code. - * - */ -int SHA1Reset(SHA1Context *context) -{ - if (!context) - { - return shaNull; - } - - context->Length_Low = 0; - context->Length_High = 0; - context->Message_Block_Index = 0; - - context->Intermediate_Hash[0] = 0x67452301; - context->Intermediate_Hash[1] = 0xEFCDAB89; - context->Intermediate_Hash[2] = 0x98BADCFE; - context->Intermediate_Hash[3] = 0x10325476; - context->Intermediate_Hash[4] = 0xC3D2E1F0; - - context->Computed = 0; - context->Corrupted = 0; - - return shaSuccess; -} - -/* - * SHA1Result - * - * Description: - * This function will return the 160-bit message digest into the - * Message_Digest array provided by the caller. - * NOTE: The first octet of hash is stored in the 0th element, - * the last octet of hash in the 19th element. - * - * Parameters: - * context: [in/out] - * The context to use to calculate the SHA-1 hash. - * Message_Digest: [out] - * Where the digest is returned. - * - * Returns: - * sha Error Code. - * - */ -int SHA1Result( SHA1Context *context, - uint8_t Message_Digest[SHA1HashSize]) -{ - int i; - - if (!context || !Message_Digest) - { - return shaNull; - } - - if (context->Corrupted) - { - return context->Corrupted; - } - - if (!context->Computed) - { - SHA1PadMessage(context); - for(i=0; i<64; ++i) - { - /* message may be sensitive, clear it out */ - context->Message_Block[i] = 0; - } - context->Length_Low = 0; /* and clear length */ - context->Length_High = 0; - context->Computed = 1; - - } - - for(i = 0; i < SHA1HashSize; ++i) - { - Message_Digest[i] = context->Intermediate_Hash[i>>2] - >> 8 * ( 3 - ( i & 0x03 ) ); - } - - return shaSuccess; -} - -/* - * SHA1Input - * - * Description: - * This function accepts an array of octets as the next portion - * of the message. - * - * Parameters: - * context: [in/out] - * The SHA context to update - * message_array: [in] - * An array of characters representing the next portion of - * the message. - * length: [in] - * The length of the message in message_array - * - * Returns: - * sha Error Code. - * - */ -int SHA1Input( SHA1Context *context, - const void *message_array0, - size_t length) -{ - const uint8_t *message_array = reinterpret_cast(message_array0); - if (!length) - { - return shaSuccess; - } - - if (!context || !message_array) - { - return shaNull; - } - - if (context->Computed) - { - context->Corrupted = shaStateError; - - return shaStateError; - } - - if (context->Corrupted) - { - return context->Corrupted; - } - while(length-- && !context->Corrupted) - { - context->Message_Block[context->Message_Block_Index++] = - (*message_array & 0xFF); - - context->Length_Low += 8; - if (context->Length_Low == 0) - { - context->Length_High++; - if (context->Length_High == 0) - { - /* Message is too long */ - context->Corrupted = 1; - } - } - - if (context->Message_Block_Index == 64) - { - SHA1ProcessMessageBlock(context); - } - - message_array++; - } - - return shaSuccess; -} - -/* - * SHA1ProcessMessageBlock - * - * Description: - * This function will process the next 512 bits of the message - * stored in the Message_Block array. - * - * Parameters: - * None. - * - * Returns: - * Nothing. - * - * Comments: - - * Many of the variable names in this code, especially the - * single character names, were used because those were the - * names used in the publication. - * - * - */ -void SHA1ProcessMessageBlock(SHA1Context *context) -{ - const uint32_t K[] = { /* Constants defined in SHA-1 */ - 0x5A827999, - 0x6ED9EBA1, - 0x8F1BBCDC, - 0xCA62C1D6 - }; - int t; /* Loop counter */ - uint32_t temp; /* Temporary word value */ - uint32_t W[80]; /* Word sequence */ - uint32_t A, B, C, D, E; /* Word buffers */ - - /* - * Initialize the first 16 words in the array W - */ - for(t = 0; t < 16; t++) - { - W[t] = context->Message_Block[t * 4] << 24; - W[t] |= context->Message_Block[t * 4 + 1] << 16; - W[t] |= context->Message_Block[t * 4 + 2] << 8; - W[t] |= context->Message_Block[t * 4 + 3]; - } - - for(t = 16; t < 80; t++) - { - W[t] = SHA1CircularShift(1,W[t-3] ^ W[t-8] ^ W[t-14] ^ W[t-16]); - } - - A = context->Intermediate_Hash[0]; - B = context->Intermediate_Hash[1]; - C = context->Intermediate_Hash[2]; - D = context->Intermediate_Hash[3]; - E = context->Intermediate_Hash[4]; - - for(t = 0; t < 20; t++) - { - temp = SHA1CircularShift(5,A) + - ((B & C) | ((~B) & D)) + E + W[t] + K[0]; - E = D; - D = C; - C = SHA1CircularShift(30,B); - - B = A; - A = temp; - } - - for(t = 20; t < 40; t++) - { - temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[1]; - E = D; - D = C; - C = SHA1CircularShift(30,B); - B = A; - A = temp; - } - - for(t = 40; t < 60; t++) - { - temp = SHA1CircularShift(5,A) + - ((B & C) | (B & D) | (C & D)) + E + W[t] + K[2]; - E = D; - D = C; - C = SHA1CircularShift(30,B); - B = A; - A = temp; - } - - for(t = 60; t < 80; t++) - { - temp = SHA1CircularShift(5,A) + (B ^ C ^ D) + E + W[t] + K[3]; - E = D; - D = C; - C = SHA1CircularShift(30,B); - B = A; - A = temp; - } - - context->Intermediate_Hash[0] += A; - context->Intermediate_Hash[1] += B; - context->Intermediate_Hash[2] += C; - context->Intermediate_Hash[3] += D; - context->Intermediate_Hash[4] += E; - - context->Message_Block_Index = 0; -} - -/* - * SHA1PadMessage - * - - * Description: - * According to the standard, the message must be padded to an even - * 512 bits. The first padding bit must be a '1'. The last 64 - * bits represent the length of the original message. All bits in - * between should be 0. This function will pad the message - * according to those rules by filling the Message_Block array - * accordingly. It will also call the ProcessMessageBlock function - * provided appropriately. When it returns, it can be assumed that - * the message digest has been computed. - * - * Parameters: - * context: [in/out] - * The context to pad - * ProcessMessageBlock: [in] - * The appropriate SHA*ProcessMessageBlock function - * Returns: - * Nothing. - * - */ - -void SHA1PadMessage(SHA1Context *context) -{ - /* - * Check to see if the current message block is too small to hold - * the initial padding bits and length. If so, we will pad the - * block, process it, and then continue padding into a second - * block. - */ - if (context->Message_Block_Index > 55) - { - context->Message_Block[context->Message_Block_Index++] = 0x80; - while(context->Message_Block_Index < 64) - { - context->Message_Block[context->Message_Block_Index++] = 0; - } - - SHA1ProcessMessageBlock(context); - - while(context->Message_Block_Index < 56) - { - context->Message_Block[context->Message_Block_Index++] = 0; - } - } - else - { - context->Message_Block[context->Message_Block_Index++] = 0x80; - while(context->Message_Block_Index < 56) - { - - context->Message_Block[context->Message_Block_Index++] = 0; - } - } - - /* - * Store the message length as the last 8 octets - */ - context->Message_Block[56] = context->Length_High >> 24; - context->Message_Block[57] = context->Length_High >> 16; - context->Message_Block[58] = context->Length_High >> 8; - context->Message_Block[59] = context->Length_High; - context->Message_Block[60] = context->Length_Low >> 24; - context->Message_Block[61] = context->Length_Low >> 16; - context->Message_Block[62] = context->Length_Low >> 8; - context->Message_Block[63] = context->Length_Low; - - SHA1ProcessMessageBlock(context); -} - -Csha1::Csha1() -{ - SHA1Reset(&m_context); -} - -Csha1::Csha1(const_memory_range s) -{ - SHA1Reset(&m_context); - write(s); -} - -void Csha1::read(void* d) -{ - SHA1Result(&m_context, reinterpret_cast(d)); -} - -std::string Csha1::read() -{ - char d[SHA1HashSize]; - read(d); - return std::string(d, SHA1HashSize); -} - -void Csha1::write(const_memory_range s) -{ - SHA1Input(&m_context, s, s.size()); -} diff --git a/install/xbt/linux/misc/sha1.h b/install/xbt/linux/misc/sha1.h deleted file mode 100644 index e26a11191..000000000 --- a/install/xbt/linux/misc/sha1.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * sha1.h - * - * Description: - * This is the header file for code which implements the Secure - * Hashing Algorithm 1 as defined in FIPS PUB 180-1 published - * April 17, 1995. - * - * Many of the variable names in this code, especially the - * single character names, were used because those were the names - * used in the publication. - * - * Please read the file sha1.c for more information. - * - */ - -#ifndef _SHA1_H_ -#define _SHA1_H_ - -#include -#include - -#ifdef WIN32 -typedef unsigned int uint32_t; -typedef int int_least16_t; -typedef unsigned char uint8_t; -#endif - -/* - * If you do not have the ISO standard stdint.h header file, then you - * must typdef the following: - * name meaning - * uint32_t unsigned 32 bit integer - * uint8_t unsigned 8 bit integer (i.e., unsigned char) - * int_least16_t integer of >= 16 bits - * - */ - -#ifndef _SHA_enum_ -#define _SHA_enum_ -enum -{ - shaSuccess = 0, - shaNull, /* Null pointer parameter */ - shaInputTooLong, /* input data too long */ - shaStateError /* called Input after Result */ -}; -#endif -#define SHA1HashSize 20 - -/* - * This structure will hold context information for the SHA-1 - * hashing operation - */ -typedef struct SHA1Context -{ - uint32_t Intermediate_Hash[SHA1HashSize/4]; /* Message Digest */ - - uint32_t Length_Low; /* Message length in bits */ - uint32_t Length_High; /* Message length in bits */ - - /* Index into message block array */ - int_least16_t Message_Block_Index; - uint8_t Message_Block[64]; /* 512-bit message blocks */ - - int Computed; /* Is the digest computed? */ - int Corrupted; /* Is the message digest corrupted? */ -} SHA1Context; - -/* - * Function Prototypes - */ - -int SHA1Reset( SHA1Context *); -int SHA1Input( SHA1Context *, - const void *, - size_t); -int SHA1Result( SHA1Context *, - uint8_t Message_Digest[SHA1HashSize]); - -class Csha1 -{ -public: - void read(void*); - std::string read(); - void write(const_memory_range); - Csha1(); - Csha1(const_memory_range); -private: - SHA1Context m_context; -}; - -#endif - diff --git a/install/xbt/linux/misc/socket.cpp b/install/xbt/linux/misc/socket.cpp deleted file mode 100644 index 20e1f2c30..000000000 --- a/install/xbt/linux/misc/socket.cpp +++ /dev/null @@ -1,223 +0,0 @@ -#include "stdafx.h" -#include "socket.h" - -#ifdef WIN32 -#pragma comment(lib, "ws2_32.lib") -#else -#include -#include -#include -#include -#include -#endif - -#ifndef INADDR_NONE -const int INADDR_NONE = -1; -#endif - -#ifndef MSG_NOSIGNAL -const int MSG_NOSIGNAL = 0; -#endif - -static bool g_start_up_done = false; - -Csocket::Csocket(SOCKET s) -{ - m_source = s == INVALID_SOCKET ? NULL : new Csocket_source(s); -} - -int Csocket::accept(int& h, int& p) -{ - sockaddr_in a; - socklen_t cb_a = sizeof(sockaddr_in); - a.sin_family = AF_INET; - int r = ::accept(*this, reinterpret_cast(&a), &cb_a); - if (r == INVALID_SOCKET) - return r; - h = a.sin_addr.s_addr; - p = a.sin_port; - return 0; -} - -int Csocket::bind(int h, int p) -{ - sockaddr_in a = {0}; - a.sin_family = AF_INET; - a.sin_addr.s_addr = h; - a.sin_port = p; - return ::bind(*this, reinterpret_cast(&a), sizeof(sockaddr_in)); -} - -int Csocket::blocking(bool v) -{ -#ifdef FIONBIO - unsigned long p = !v; - return ioctlsocket(*this, FIONBIO, &p); -#else - return fcntl(*this, F_SETFL, v ? 0 : O_NONBLOCK) == -1; -#endif -} - -void Csocket::close() -{ - *this = INVALID_SOCKET; -} - -int Csocket::connect(int h, int p) -{ - sockaddr_in a = {0}; - a.sin_family = AF_INET; - a.sin_addr.s_addr = h; - a.sin_port = p; - return ::connect(*this, reinterpret_cast(&a), sizeof(sockaddr_in)); -} - -int Csocket::listen() -{ - return ::listen(*this, SOMAXCONN); -} - -const Csocket& Csocket::open(int t, bool _blocking) -{ - start_up(); - *this = socket(AF_INET, t, 0); - if (*this != INVALID_SOCKET && !_blocking && blocking(false)) - close(); - return *this; -} - -int Csocket::recv(memory_range d) const -{ - return ::recv(*this, reinterpret_cast(d.begin), d.size(), MSG_NOSIGNAL); -} - -int Csocket::recvfrom(memory_range d, sockaddr* a, socklen_t* cb_a) const -{ - return ::recvfrom(*this, reinterpret_cast(d.begin), d.size(), MSG_NOSIGNAL, a, cb_a); -} - -int Csocket::send(const_memory_range s) const -{ - return ::send(*this, reinterpret_cast(s.begin), s.size(), MSG_NOSIGNAL); -} - -int Csocket::sendto(const_memory_range s, const sockaddr* a, socklen_t cb_a) const -{ - return ::sendto(*this, reinterpret_cast(s.begin), s.size(), MSG_NOSIGNAL, a, cb_a); -} - -int Csocket::getsockopt(int level, int name, void* v, socklen_t& cb_v) -{ - return ::getsockopt(*this, level, name, reinterpret_cast(v), &cb_v); -} - -int Csocket::getsockopt(int level, int name, int& v) -{ - socklen_t cb_v = sizeof(int); - return getsockopt(level, name, &v, cb_v); -} - -int Csocket::setsockopt(int level, int name, const void* v, int cb_v) -{ - return ::setsockopt(*this, level, name, reinterpret_cast(v), cb_v); -} - -int Csocket::setsockopt(int level, int name, int v) -{ - return setsockopt(level, name, &v, sizeof(int)); -} - -int Csocket::get_host(const std::string& name) -{ - hostent* e = gethostbyname(name.c_str()); - return e && e->h_addrtype == AF_INET && e->h_length == sizeof(in_addr) && e->h_addr_list ? *reinterpret_cast(*e->h_addr_list) : INADDR_NONE; -} - -std::string Csocket::error2a(int v) -{ - switch (v) - { - case WSAEACCES: return "EACCES"; - case WSAEADDRINUSE: return "EADDRINUSE"; - case WSAEADDRNOTAVAIL: return "EADDRNOTAVAIL"; - case WSAEAFNOSUPPORT: return "EAFNOSUPPORT"; - case WSAEALREADY: return "EALREADY"; - case WSAEBADF: return "EBADF"; - case WSAECONNABORTED: return "ECONNABORTED"; - case WSAECONNREFUSED: return "ECONNREFUSED"; - case WSAECONNRESET: return "ECONNRESET"; - case WSAEDESTADDRREQ: return "EDESTADDRREQ"; - case WSAEDQUOT: return "EDQUOT"; - case WSAEFAULT: return "EFAULT"; - case WSAEHOSTDOWN: return "EHOSTDOWN"; - case WSAEHOSTUNREACH: return "EHOSTUNREACH"; - case WSAEINPROGRESS: return "EINPROGRESS"; - case WSAEINTR: return "EINTR"; - case WSAEINVAL: return "EINVAL"; - case WSAEISCONN: return "EISCONN"; - case WSAELOOP: return "ELOOP"; - case WSAEMFILE: return "EMFILE"; - case WSAEMSGSIZE: return "EMSGSIZE"; - case WSAENAMETOOLONG: return "ENAMETOOLONG"; - case WSAENETDOWN: return "ENETDOWN"; - case WSAENETRESET: return "ENETRESET"; - case WSAENETUNREACH: return "ENETUNREACH"; - case WSAENOBUFS: return "ENOBUFS"; - case WSAENOPROTOOPT: return "ENOPROTOOPT"; - case WSAENOTCONN: return "ENOTCONN"; - case WSAENOTEMPTY: return "ENOTEMPTY"; - case WSAENOTSOCK: return "ENOTSOCK"; - case WSAEOPNOTSUPP: return "EOPNOTSUPP"; - case WSAEPFNOSUPPORT: return "EPFNOSUPPORT"; - case WSAEPROTONOSUPPORT: return "EPROTONOSUPPORT"; - case WSAEPROTOTYPE: return "EPROTOTYPE"; - case WSAEREMOTE: return "EREMOTE"; - case WSAESHUTDOWN: return "ESHUTDOWN"; - case WSAESOCKTNOSUPPORT: return "ESOCKTNOSUPPORT"; - case WSAESTALE: return "ESTALE"; - case WSAETIMEDOUT: return "ETIMEDOUT"; - case WSAETOOMANYREFS: return "ETOOMANYREFS"; - case WSAEUSERS: return "EUSERS"; - case WSAEWOULDBLOCK: return "EWOULDBLOCK"; -#ifdef WIN32 - case WSAECANCELLED: return "ECANCELLED"; - case WSAEDISCON: return "EDISCON"; - case WSAEINVALIDPROCTABLE: return "EINVALIDPROCTABLE"; - case WSAEINVALIDPROVIDER: return "EINVALIDPROVIDER"; - case WSAENOMORE: return "ENOMORE"; - case WSAEPROVIDERFAILEDINIT: return "EPROVIDERFAILEDINIT"; - case WSAEREFUSED: return "EREFUSED"; - case WSANOTINITIALISED: return "NOTINITIALISED"; - case WSASERVICE_NOT_FOUND: return "SERVICE_NOT_FOUND"; - case WSASYSCALLFAILURE: return "SYSCALLFAILURE"; - case WSASYSNOTREADY: return "SYSNOTREADY"; - case WSATYPE_NOT_FOUND: return "TYPE_NOT_FOUND"; - case WSAVERNOTSUPPORTED: return "VERNOTSUPPORTED"; - case WSA_E_CANCELLED: return "E_CANCELLED"; - case WSA_E_NO_MORE: return "E_NO_MORE"; -#endif - } - char b[12]; - sprintf(b, "%d", v); - return b; -} - -std::string Csocket::inet_ntoa(int v) -{ - in_addr a; - a.s_addr = v; - return ::inet_ntoa(a); -} - -int Csocket::start_up() -{ - if (g_start_up_done) - return 0; - g_start_up_done = true; -#ifdef WIN32 - WSADATA wsadata; - if (WSAStartup(MAKEWORD(2, 0), &wsadata)) - return 1; -#endif - return 0; -} diff --git a/install/xbt/linux/misc/socket.h b/install/xbt/linux/misc/socket.h deleted file mode 100644 index 2273bdbd0..000000000 --- a/install/xbt/linux/misc/socket.h +++ /dev/null @@ -1,135 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#ifdef WIN32 -#include - -typedef int socklen_t; -#else -#include -#include -#include - -#define closesocket close -#define ioctlsocket ioctl -#define WSAGetLastError() errno - -#define WSAEACCES EACCES -#define WSAEADDRINUSE EADDRINUSE -#define WSAEADDRNOTAVAIL EADDRNOTAVAIL -#define WSAEAFNOSUPPORT EAFNOSUPPORT -#define WSAEALREADY EALREADY -#define WSAEBADF EBADF -#define WSAECONNABORTED ECONNABORTED -#define WSAECONNREFUSED ECONNREFUSED -#define WSAECONNRESET ECONNRESET -#define WSAEDESTADDRREQ EDESTADDRREQ -#define WSAEDQUOT EDQUOT -#define WSAEFAULT EFAULT -#define WSAEHOSTDOWN EHOSTDOWN -#define WSAEHOSTUNREACH EHOSTUNREACH -#define WSAEINPROGRESS EINPROGRESS -#define WSAEINTR EINTR -#define WSAEINVAL EINVAL -#define WSAEISCONN EISCONN -#define WSAELOOP ELOOP -#define WSAEMFILE EMFILE -#define WSAEMSGSIZE EMSGSIZE -#define WSAENAMETOOLONG ENAMETOOLONG -#define WSAENETDOWN ENETDOWN -#define WSAENETRESET ENETRESET -#define WSAENETUNREACH ENETUNREACH -#define WSAENOBUFS ENOBUFS -#define WSAENOPROTOOPT ENOPROTOOPT -#define WSAENOTCONN ENOTCONN -#define WSAENOTEMPTY ENOTEMPTY -#define WSAENOTSOCK ENOTSOCK -#define WSAEOPNOTSUPP EOPNOTSUPP -#define WSAEPFNOSUPPORT EPFNOSUPPORT -#define WSAEPROTONOSUPPORT EPROTONOSUPPORT -#define WSAEPROTOTYPE EPROTOTYPE -#define WSAEREMOTE EREMOTE -#define WSAESHUTDOWN ESHUTDOWN -#define WSAESOCKTNOSUPPORT ESOCKTNOSUPPORT -#define WSAESTALE ESTALE -#define WSAETIMEDOUT ETIMEDOUT -#define WSAETOOMANYREFS ETOOMANYREFS -#define WSAEUSERS EUSERS -#define WSAEWOULDBLOCK EWOULDBLOCK - -typedef int SOCKET; - -const int INVALID_SOCKET = -1; -const int SOCKET_ERROR = -1; -#endif - -class Csocket_source: boost::noncopyable -{ -public: - Csocket_source(SOCKET s) - { - m_s = s; - mc_references = 0; - } - - ~Csocket_source() - { - closesocket(m_s); - } - - operator SOCKET() const - { - return m_s; - } - - friend void intrusive_ptr_add_ref(Csocket_source* v) - { - v->mc_references++; - } - - friend void intrusive_ptr_release(Csocket_source* v) - { - v->mc_references--; - if (!v->mc_references) - delete v; - } -private: - SOCKET m_s; - int mc_references; -}; - -class Csocket -{ -public: - static std::string error2a(int v); - static int get_host(const std::string& name); - static std::string inet_ntoa(int h); - static int start_up(); - int accept(int& h, int& p); - int bind(int h, int p); - int blocking(bool v); - void close(); - int connect(int h, int p); - int getsockopt(int level, int name, void* v, socklen_t& cb_v); - int getsockopt(int level, int name, int& v); - int listen(); - const Csocket& open(int t, bool blocking = false); - int recv(memory_range) const; - int recvfrom(memory_range, sockaddr* a, socklen_t* cb_a) const; - int send(const_memory_range) const; - int sendto(const_memory_range, const sockaddr* a, socklen_t cb_a) const; - int setsockopt(int level, int name, const void* v, int cb_v); - int setsockopt(int level, int name, int v); - Csocket(SOCKET = INVALID_SOCKET); - - operator SOCKET() const - { - return m_source ? static_cast(*m_source) : INVALID_SOCKET; - } -private: - boost::intrusive_ptr m_source; -}; diff --git a/install/xbt/linux/misc/sql/database.cpp b/install/xbt/linux/misc/sql/database.cpp deleted file mode 100644 index 67d739f56..000000000 --- a/install/xbt/linux/misc/sql/database.cpp +++ /dev/null @@ -1,71 +0,0 @@ -#include "stdafx.h" -#include "database.h" - -#include -#include -#include - -#ifdef WIN32 -#pragma comment(lib, "libmysql") -#else -#include -#endif - -Cdatabase::Cdatabase() -{ - mysql_init(&m_handle); -} - -Cdatabase::~Cdatabase() -{ - close(); -} - -void Cdatabase::open(const std::string& host, const std::string& user, const std::string& password, const std::string& database, bool echo_errors) -{ - m_echo_errors = echo_errors; - if (!mysql_init(&m_handle) || mysql_options(&m_handle, MYSQL_READ_DEFAULT_GROUP, "") || !mysql_real_connect(&m_handle, host.c_str(), user.c_str(), password.empty() ? NULL : password.c_str(), database.c_str(), 0, NULL, 0)) - throw exception(mysql_error(&m_handle)); - char a0 = true; - mysql_options(&m_handle, MYSQL_OPT_RECONNECT, &a0); -} - -Csql_result Cdatabase::query(const std::string& q) -{ - if (!m_query_log.empty()) - { - static std::ofstream f(m_query_log.c_str()); - f << q.substr(0, 239) << std::endl; - } - if (mysql_real_query(&m_handle, q.data(), q.size())) - { - if (m_echo_errors) - { - std::cerr << mysql_error(&m_handle) << std::endl - << q.substr(0, 239) << std::endl; - } -#ifndef WIN32 - syslog(LOG_ERR, "%s", mysql_error(&m_handle)); -#endif - throw exception(mysql_error(&m_handle)); - } - MYSQL_RES* result = mysql_store_result(&m_handle); - if (!result && mysql_errno(&m_handle)) - throw exception(mysql_error(&m_handle)); - return Csql_result(result); -} - -void Cdatabase::close() -{ - mysql_close(&m_handle); -} - -int Cdatabase::insert_id() -{ - return mysql_insert_id(&m_handle); -} - -void Cdatabase::set_query_log(const std::string& v) -{ - m_query_log = v; -} diff --git a/install/xbt/linux/misc/sql/database.h b/install/xbt/linux/misc/sql/database.h deleted file mode 100644 index 325908689..000000000 --- a/install/xbt/linux/misc/sql/database.h +++ /dev/null @@ -1,33 +0,0 @@ -#pragma once - -#include -#include "sql_result.h" - -class Cdatabase: boost::noncopyable -{ -public: - class exception: public std::runtime_error - { - public: - exception(const std::string& s): runtime_error(s) - { - } - }; - - void open(const std::string& host, const std::string& user, const std::string& password, const std::string& database, bool echo_errors = false); - Csql_result query(const std::string&); - void set_query_log(const std::string&); - int insert_id(); - void close(); - Cdatabase(); - ~Cdatabase(); - - MYSQL* handle() - { - return &m_handle; - } -private: - bool m_echo_errors; - MYSQL m_handle; - std::string m_query_log; -}; diff --git a/install/xbt/linux/misc/sql/sql_query.cpp b/install/xbt/linux/misc/sql/sql_query.cpp deleted file mode 100644 index ebd8e6aee..000000000 --- a/install/xbt/linux/misc/sql/sql_query.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "stdafx.h" -#include "sql_query.h" - -#include -#include -#include "database.h" - -Csql_query::Csql_query(Cdatabase& database, const std::string& v): - m_database(database) -{ - m_in = v; -} - -Csql_result Csql_query::execute() const -{ - return m_database.query(read()); -} - -std::string Csql_query::read() const -{ - return m_out + m_in; -} - -void Csql_query::operator=(const std::string& v) -{ - m_in = v; - m_out.clear(); -} - -void Csql_query::operator+=(const std::string& v) -{ - m_in += v; -} - -Csql_query& Csql_query::p_name(const std::string& v) -{ - std::vector r(2 * v.size() + 2); - r.resize(mysql_real_escape_string(m_database.handle(), &r.front() + 1, v.data(), v.size()) + 2); - r.front() = '`'; - r.back() = '`'; - p_raw(r); - return *this; -} - -Csql_query& Csql_query::p_raw(const_memory_range v) -{ - size_t i = m_in.find('?'); - m_out.append(m_in.data(), i); - if (i == std::string::npos) - m_in.clear(); - else - m_in.erase(0, i + 1); - m_out.append(v.begin, v.end); - return *this; -} - -Csql_query& Csql_query::p(long long v) -{ - char b[21]; -#ifdef WIN32 - sprintf(b, "%I64d", v); -#else - sprintf(b, "%lld", v); -#endif - p_raw(const_memory_range(b)); - return *this; -} - -Csql_query& Csql_query::p(const_memory_range v) -{ - std::vector r(2 * v.size() + 2); - r.resize(mysql_real_escape_string(m_database.handle(), &r.front() + 1, reinterpret_cast(v.begin), v.size()) + 2); - r.front() = '\''; - r.back() = '\''; - p_raw(r); - return *this; -} diff --git a/install/xbt/linux/misc/sql/sql_query.h b/install/xbt/linux/misc/sql/sql_query.h deleted file mode 100644 index 0f691e384..000000000 --- a/install/xbt/linux/misc/sql/sql_query.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include - -class Cdatabase; -class Csql_result; - -class Csql_query -{ -public: - Csql_result execute() const; - std::string read() const; - void operator=(const std::string&); - void operator+=(const std::string&); - Csql_query& p_name(const std::string&); - Csql_query& p_raw(const_memory_range); - Csql_query& p(long long); - Csql_query& p(const_memory_range); - Csql_query(Cdatabase&, const std::string& = ""); -private: - std::string m_in; - std::string m_out; - Cdatabase& m_database; -}; diff --git a/install/xbt/linux/misc/sql/sql_result.cpp b/install/xbt/linux/misc/sql/sql_result.cpp deleted file mode 100644 index 82a557f83..000000000 --- a/install/xbt/linux/misc/sql/sql_result.cpp +++ /dev/null @@ -1,15 +0,0 @@ -#include "stdafx.h" -#include "sql_result.h" - -Csql_row::Csql_row(MYSQL_ROW data, unsigned long* sizes, const boost::shared_ptr& source) -{ - m_data = data; - m_sizes = sizes; - m_source = source; -} - -Csql_row Csql_result::fetch_row() const -{ - MYSQL_ROW data = mysql_fetch_row(h()); - return Csql_row(data, mysql_fetch_lengths(h()), m_source); -} diff --git a/install/xbt/linux/misc/sql/sql_result.h b/install/xbt/linux/misc/sql/sql_result.h deleted file mode 100644 index 5ef5ee1ae..000000000 --- a/install/xbt/linux/misc/sql/sql_result.h +++ /dev/null @@ -1,142 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#ifdef _MSC_VER -#include -#include -#else -#include -#endif - -class Csql_result_source: boost::noncopyable -{ -public: - Csql_result_source(MYSQL_RES* h) - { - m_h = h; - } - - ~Csql_result_source() - { - mysql_free_result(m_h); - } - - MYSQL_RES* h() const - { - return m_h; - } -private: - MYSQL_RES* m_h; -}; - -class Csql_field -{ -public: - Csql_field(const char* begin, int size) - { - m_begin = begin; - m_size = size; - } - - const char* raw() const - { - return m_begin; - } - - int size() const - { - return m_size; - } - - float f(float d = 0) const - { - return raw() ? atof(raw()) : d; - } - - long long i(long long d = 0) const - { -#ifdef WIN32 - return raw() ? _atoi64(raw()) : d; -#else - return raw() ? atoll(raw()) : d; -#endif - } - - const std::string s(const std::string& d = "") const - { - return raw() ? std::string(raw(), size()) : d; - } - - const_memory_range vdata() const - { - return const_memory_range(raw(), size()); - } -private: - const char* m_begin; - int m_size; -}; - -class Csql_row -{ -public: - Csql_row(MYSQL_ROW, unsigned long* sizes, const boost::shared_ptr&); - - Csql_row() - { - } - - operator bool() const - { - return m_data; - } - - Csql_field operator[](size_t i) const - { - return Csql_field(m_data[i], m_sizes[i]); - } -private: - MYSQL_ROW m_data; - unsigned long* m_sizes; - boost::shared_ptr m_source; -}; - -class Csql_result -{ -public: - Csql_row fetch_row() const; - - Csql_result(MYSQL_RES* h) - { - m_source = boost::make_shared(h); - } - - operator bool() const - { - return c_rows(); - } - - int c_fields() const - { - return mysql_num_fields(h()); - } - - int c_rows() const - { - return mysql_num_rows(h()); - } - - void data_seek(int i) - { - mysql_data_seek(h(), i); - } -private: - MYSQL_RES* h() const - { - return m_source->h(); - } - - boost::shared_ptr m_source; -}; diff --git a/install/xbt/linux/misc/stream_int.h b/install/xbt/linux/misc/stream_int.h deleted file mode 100644 index a008182aa..000000000 --- a/install/xbt/linux/misc/stream_int.h +++ /dev/null @@ -1,83 +0,0 @@ -#pragma once - -#include -#include - -inline float read_float(const void* r) -{ - float v; - memcpy(&v, r, sizeof(float)); - return v; -} - -inline float read_float(const void* r0, const void* s_end) -{ - return read_float(r0); -} - -template -static T write_float(T w0, float v) -{ - unsigned char* w = reinterpret_cast(w0); - memcpy(w, &v, sizeof(float)); - return w + sizeof(float); -} - -inline long long read_int(int cb, const void* r0) -{ - const unsigned char* r = reinterpret_cast(r0); - long long v = 0; - while (cb--) - v = v << 8 | *r++; - return v; -} - -inline long long read_int(int cb, const_memory_range s) -{ - return s.size() < cb ? 0 : read_int(cb, s.begin); -} - -inline long long read_int(int cb, const void* r, const void* s_end) -{ - return read_int(cb, const_memory_range(r, s_end)); -} - -template -T write_int(int cb, T w0, long long v) -{ - unsigned char* w = reinterpret_cast(w0); - w += cb; - for (int i = 0; i < cb; i++) - { - *--w = v & 0xff; - v >>= 8; - } - return reinterpret_cast(w + cb); -} - -inline long long read_int_le(int cb, const void* r0) -{ - const unsigned char* r = reinterpret_cast(r0); - r += cb; - long long v = 0; - while (cb--) - v = v << 8 | *--r; - return v; -} - -inline long long read_int_le(int cb, const void* r, const void* s_end) -{ - return read_int_le(cb, r); -} - -template -T write_int_le(int cb, T w0, long long v) -{ - unsigned char* w = reinterpret_cast(w0); - for (int i = 0; i < cb; i++) - { - *w++ = v & 0xff; - v >>= 8; - } - return reinterpret_cast(w); -} diff --git a/install/xbt/linux/misc/stream_reader.cpp b/install/xbt/linux/misc/stream_reader.cpp deleted file mode 100644 index f57d5ba6a..000000000 --- a/install/xbt/linux/misc/stream_reader.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "stdafx.h" -#include "stream_reader.h" - diff --git a/install/xbt/linux/misc/stream_reader.h b/install/xbt/linux/misc/stream_reader.h deleted file mode 100644 index 15e78fbe1..000000000 --- a/install/xbt/linux/misc/stream_reader.h +++ /dev/null @@ -1,59 +0,0 @@ -#pragma once - -#include -#include - -class Cstream_reader -{ -public: - const unsigned char* d() const - { - return m_d; - } - - const unsigned char* d_end() const - { - return m_d.end(); - } - - const unsigned char* r() const - { - return m_r; - } - - const unsigned char* read(int size) - { - m_r += size; - return m_r - size; - } - - long long read_int(int cb) - { - m_r += cb; - return ::read_int(cb, m_r - cb); - } - - Cvirtual_binary read_data() - { - int l = read_int(4); - return Cvirtual_binary(const_memory_range(read(l), l)); - } - - std::string read_string() - { - int l = read_int(4); - return std::string(reinterpret_cast(read(l)), l); - } - - Cstream_reader() - { - } - - Cstream_reader(const Cvirtual_binary& d) - { - m_r = m_d = d; - } -private: - Cvirtual_binary m_d; - const unsigned char* m_r; -}; diff --git a/install/xbt/linux/misc/stream_writer.cpp b/install/xbt/linux/misc/stream_writer.cpp deleted file mode 100644 index 88041c56b..000000000 --- a/install/xbt/linux/misc/stream_writer.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "stdafx.h" -#include "stream_writer.h" diff --git a/install/xbt/linux/misc/stream_writer.h b/install/xbt/linux/misc/stream_writer.h deleted file mode 100644 index 108f4c483..000000000 --- a/install/xbt/linux/misc/stream_writer.h +++ /dev/null @@ -1,41 +0,0 @@ -#pragma once - -#include -#include - -class Cstream_writer -{ -public: - unsigned char* w() const - { - return m_w; - } - - unsigned char* write(int size) - { - m_w += size; - return m_w - size; - } - - void write_int(int cb, long long v) - { - m_w = ::write_int(cb, m_w, v); - } - - void write_data(const_memory_range v) - { - write_int(4, v.size()); - memcpy(write(v.size()), v, v.size()); - } - - Cstream_writer() - { - } - - Cstream_writer(unsigned char* w) - { - m_w = w; - } -private: - unsigned char* m_w; -}; diff --git a/install/xbt/linux/misc/tf_misc.cpp b/install/xbt/linux/misc/tf_misc.cpp deleted file mode 100644 index 5a3927f78..000000000 --- a/install/xbt/linux/misc/tf_misc.cpp +++ /dev/null @@ -1,170 +0,0 @@ -#include "stdafx.h" -#include "tf_misc.h" - -#include -#include - -static std::string web_encode(const std::string& v) -{ - std::string d; - d.reserve(v.size() << 1); - for (int a = 0; a < v.size();) - { - int b = v.find_first_of("\"<&", a); - if (b == std::string::npos) - { - d += v.substr(a); - return d; - } - d += v.substr(a, b - a); - switch (v[b]) - { - case '"': - d += """; - break; - case '<': - d += "<"; - break; - case '&': - d += "&"; - break; - } - a = b + 1; - } - return d; -} - -static std::string web_link(const std::string& link_title, const std::string& link, bool encode) -{ - return encode - ? web_link(web_encode(link_title), web_encode(link), false) - : (boost::format("%s") % link % (link_title.empty() ? link : link_title)).str(); -} - -static std::string encode_local_url(const std::string& url, const std::string& local_domain_url) -{ - if (!local_domain_url.empty() && boost::istarts_with(url, local_domain_url)) - return url.substr(local_domain_url.length()); - return url; -} - -std::string encode_field(const std::string& v, const std::string& local_domain_url) -{ - std::string r; - r.reserve(v.length() << 1); - for (size_t i = 0; i < v.length(); ) - { - if (boost::istarts_with(v.c_str() + i, "ftp.") - || boost::istarts_with(v.c_str() + i, "ftp://") - || boost::istarts_with(v.c_str() + i, "http://") - || boost::istarts_with(v.c_str() + i, "https://") - || boost::istarts_with(v.c_str() + i, "mailto:") - || boost::istarts_with(v.c_str() + i, "www.")) - { - size_t p = i; - while (p < v.length() - && !isspace(v[p] & 0xff) - && v[p] != '\"' - && v[p] != '<' - && v[p] != '>') - { - p++; - } - if (v[p - 1] == '!' || v[p - 1] == ',' || v[p - 1] == '.' || v[p - 1] == '?') - p--; - if (v[p - 1] == ')') - p--; - std::string url = web_encode(v.substr(i, p - i)); - if (boost::istarts_with(v.c_str() + i, "ftp.")) - r += web_link(url, "ftp://" + url, false); - else if (boost::istarts_with(v.c_str() + i, "www.")) - r += web_link(url, "http://" + url, false); - else - r += web_link(boost::istarts_with(v.c_str() + i, "mailto:") ? url.substr(7) : encode_local_url(url, local_domain_url), url, false); - i = p; - } - else - { - char c = v[i++]; - switch (c) - { - case '<': - r += "<"; - break; - case '&': - r += "&"; - break; - default: - r += c; - } - } - } - return r; -} - -std::string encode_text(const std::string& v, const std::string& local_domain_url, bool add_span) -{ - std::string r; - r.reserve(v.length() << 1); - for (size_t i = 0; i < v.length(); ) - { - size_t p = v.find('\n', i); - if (p == std::string::npos) - p = v.length(); - std::string line = v.substr(i, p - i); - line = encode_field(line, local_domain_url); - r += add_span && boost::istarts_with(line, "> ") ? "" + line + "" : line; - r += "
"; - i = p + 1; - } - return r; -} - -std::string trim_field(const std::string& v) -{ - std::string r; - bool copy_white = false; - for (size_t i = 0; i < v.length(); i++) - { - if (isspace(v[i] & 0xff)) - copy_white = true; - else - { - if (copy_white) - { - if (!r.empty()) - r += ' '; - copy_white = false; - } - r += v[i]; - } - } - return r; -} - -std::string trim_text(const std::string& v) -{ - std::string r; - bool copy_white = false; - for (size_t i = 0; i < v.length(); ) - { - size_t p = v.find('\n', i); - if (p == std::string::npos) - p = v.length(); - std::string line = trim_field(v.substr(i, p - i)); - if (line.empty()) - copy_white = true; - else - { - if (copy_white) - { - if (!r.empty()) - r += '\n'; - copy_white = false; - } - r += line + '\n'; - } - i = p + 1; - } - return r; -} diff --git a/install/xbt/linux/misc/tf_misc.h b/install/xbt/linux/misc/tf_misc.h deleted file mode 100644 index e9d8d0017..000000000 --- a/install/xbt/linux/misc/tf_misc.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once - -#include - -std::string encode_field(const std::string&, const std::string& local_domain_url); -std::string encode_text(const std::string&, const std::string& local_domain_url, bool add_span); -std::string trim_field(const std::string&); -std::string trim_text(const std::string&); diff --git a/install/xbt/linux/misc/virtual_binary.cpp b/install/xbt/linux/misc/virtual_binary.cpp deleted file mode 100644 index caaa208fd..000000000 --- a/install/xbt/linux/misc/virtual_binary.cpp +++ /dev/null @@ -1,75 +0,0 @@ -#include "stdafx.h" -#include "xbt/virtual_binary.h" - -#include -#include -#include - -Cvirtual_binary_source::Cvirtual_binary_source(const_memory_range d) -{ - m_range.begin = new unsigned char[d.size()]; - m_range.end = m_range.begin + d.size(); - if (d) - memcpy(m_range, d, d.size()); -} - -Cvirtual_binary::Cvirtual_binary(size_t v) -{ - m_source = boost::make_shared(const_memory_range(NULL, v)); -} - -Cvirtual_binary::Cvirtual_binary(const_memory_range d) -{ - m_source = boost::make_shared(d); -} - -int Cvirtual_binary::save(const std::string& fname) const -{ - FILE* f = fopen(fname.c_str(), "wb"); - if (!f) - return 1; - int error = fwrite(data(), 1, size(), f) != size(); - fclose(f); - return error; -} - -int Cvirtual_binary::load(const std::string& fname) -{ - FILE* f = fopen(fname.c_str(), "rb"); - if (!f) - return 1; - struct stat b; - int error = fstat(fileno(f), &b) ? 1 : fread(write_start(b.st_size), 1, b.st_size, f) != b.st_size; - fclose(f); - return error; -} - -Cvirtual_binary& Cvirtual_binary::load1(const std::string& fname) -{ - load(fname); - return *this; -} - -void Cvirtual_binary::clear() -{ - m_source.reset(); -} - -size_t Cvirtual_binary::read(void* d) const -{ - memcpy(d, data(), size()); - return size(); -} - -unsigned char* Cvirtual_binary::write_start(size_t cb_d) -{ - if (data() && size() == cb_d) - return data_edit(); - m_source = boost::make_shared(const_memory_range(NULL, cb_d)); - return data_edit(); -} - -void Cvirtual_binary::write(const_memory_range d) -{ - memcpy(write_start(d.size()), d, d.size()); -} diff --git a/install/xbt/linux/misc/windows/ETSLayout.cpp b/install/xbt/linux/misc/windows/ETSLayout.cpp deleted file mode 100644 index 222ba77bf..000000000 --- a/install/xbt/linux/misc/windows/ETSLayout.cpp +++ /dev/null @@ -1,3058 +0,0 @@ -//////////////////////////////////////////// -// ___ ____ _________________ // -// / _/_ _// _______________/ // -// / _/ / / / / ___ ___ ____ // -// /__/ /_/ / / / // _/_ _/ // -// _________/ / / / // _/ / / // -// (c) 1998-2000_/ /___//_/ /_/ // -// // -//////////////////////////////////////////// -// all rights reserved // -//////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// ETSLayoutDialog -// -// A class for smart layouting of Dialogs and such -// -// USAGE: See LayoutMgr.html -// -// AUTHOR: Erwin Tratar -// -// DISCLAIMER: -// -// This Sourcecode and all accompaning material is 1998-1999 Erwin Tratar. -// All rights reserved. -// -// The source code may be used in compiled form in any way you desire -// (including usage in commercial applications), providing that your -// application adds essential code (i.e. it is not only a wrapper) to the -// functionality found here -// -// Redistribution of the sourcecode itself, publication in any media or -// inclusion in a library requires the authors expressed written consent. -// You may not sale this code for profit. -// -// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. USE IT -// AT YOUR OWN RISK! THE AUTHOR ACCEPTS NO LIABILITY FOR ANY DAMAGE/LOSS OF -// BUSINESS THAT THIS PRODUCT MAY CAUSE. -// -// -// HISTORY: -// 1998/05/1 Initial Release -// 1998/05/13 Added ability to have a Pane with a control -// 1998/05/13 Added better support for TabControls -// 1998/05/14 automatically set Icon to IDR_MAINFRAME -// 1998/05/19 no flicker on restoring position in OnInitialUpdate -// Changed procedure for load/save, see constructor -// 1998/10/02 Added support for Maximum (tracking) size -// 1998/10/02 Much improved handling regarding RELATIVE/GREEDY -// /w critical minimum size -// 1998/10/02 turn on/off gripper at lower right corner -// 1998/10/05 Support for user defined minimum size for items -// (was hardcoded 5 before) -// 1998/10/07 Fix for FormViews -// 1998/10/31 Support for SECDialogBar/CDialogBar -// 1998/10/31 simplified interface -// 1998/10/31 Advanced positioning options -// 1998/10/31 Added paneNull for empty Pane (former: NULL) -// 1998/11/20 Swapped ETSLayoutDialog constructor parameters -// 1998/11/20 Added Pane::addItemSpaceBetween -// [Leo Zelevinsky] -// 1998/11/24 Added fixup for greedy panes -// 1998/11/24 addItemSpaceBetween now subtracts 2*nDefaultBorder -// 1998/11/24 addGrowing() added as a shortcut for a paneNull -// 1998/11/24 simplified interface: no more PaneBase:: / Pane:: -// needed -// 1998/11/24 added FILL_* Modes -// 1998/11/24 improved maximum size handling for greedy panes -// 1998/11/25 Fixup of greedy panes caused infinite loop in some -// cases -// 1999/01/07 addItemSpaceLike() added -// 1999/04/03 Fixed ETSLayoutFormView memory leak -// 1999/04/07 Fixed ALIGN_xCENTER -// 1999/04/08 New simple stream-interface added -// 1999/04/09 Added support for an empty Status-Bar for resizing -// instead of a gripper in the lower right corner -// [Andreas Kapust] -// 1999/04/11 New code for much less flickering, OnEraseBkgnd() -// overidden for this task -// 1999/05/12 Split Layout code into understandable pieces and adding -// a lot of comments -// 1999/06/20 ABSOLUTE_X + ALIGN_FILL_X expands item if there is any -// left space (after all Abs/Rel/Greedy processing is done) -// 1999/10/06 Changed Load() and Save() to use WINDOWPLACEMENT -// [Keith Bussell] -// 1999/11/18 Added possibility to add panes of the same orientation -// to another pane. This merges both panes in one big -// pane with the same orientation -// 1999/11/18 Added support for BCGDialogBar (only with BCG > 4.52!) -// 1999/11/25 Addes support for PropertyPages/Sheets. Uses some code -// of a code submission from Anreas Kapust -// 1999/11/25 Renamed classes to ETSLayoutXXX -// 1999/11/25 Use CreateRoot() and Root() instead of m_pRootPane in -// derived class. -// 1999/11/26 Added autopointer support. No need to use normal pointers -// when defining layout anymore. Changed m_pRootPane to -// m_RootPane -// 1999/11/26 Bug in Fixup Greedy II with multiple GREEDY panes and one -// of them min/max limited -// 1999/11/28 Fixed PaneTab::getConstrainVert() for ABSOLUTE_VERT -// 1999/11/28 Fixed itemFixed() -// 1999/11/28 Changed DWORD modeResize Arguments to layModeResize for -// better type safety. Added typesafe operator| -// 1999/12/04 Don't reposition window in UpdateLayout if it's a child -// (as a child Dialog or PropertyPage) -// 1999/12/04 Erase Backgroung with GCL_HBRBACKGROUND (if available) -// 1999/12/04 itemSpaceXXX() adds a NORESIZE item instead of ABSOLUTE_XXX -// this will fix unwanted growing in secondary direction -// -// Version: 1.0 [1999/12/04] Initial Article on CodeProject -// -// 1999/12/10 Erase Backgroung within TabCtrl was 'fixed' badly. Reverted to -// old working code -// 2000/02/02 When the Dialog is child of a View the class works correctly -// now [Didier BULTIAUW] -// 2000/02/15 Combo-Boxes were not working correctly (in all modes!) -// 2000/02/17 aligned SpinButton Controls (with buddy) now handled -// automatically -// !! do not add such a control to the layout !! it is always -// reattached to its buddy. -// 2000/02/17 changed some cotrol class names to the defined constants -// -// Version: 1.1 [2000/02/17] -// -// 2000/02/25 Fixed auto alignment of SpinButton Controls to only affect -// visible ones -// 2000/02/27 Put all the classes into the namespace 'ETSLayout' -// 2000/03/07 Fixed growing Dialog after minimizing and restoring -// 2000/05/22 Whole Statusbar (Gripper) is not excluded anymore in EraseBkgnd() -// instead only the triangular Gripper is excluded -// 2000/05/31 Fix for PropertySheets with PSH_WIZARDHASFINISH [Thmmi] -// 2000/05/31 Fix for UpDown-Controls with EditCtrl Buddy in PropertyPages. -// These were not repositioned every time the page is being show -// until the first resize -// 2000/07/28 Problems with resizing ActiveX Controls fixed [Micheal Chapman] -// 2000/07/28 Some strings were not properly wrapped with _T() -// 2000/08/03 Check for BS_GROUPBOX was not correct as BS_GROUPBOX is more than one Bit -// 2000/08/03 New override AddMainArea added to ETSLayoutPropertySheet in order to -// have a hook for additional controls in a PropertySheet (besides the Tab) -// 2000/08/03 New override AddButtons added to ETSLayoutPropertySheet in order to -// have a hook for additional controls in the bottem pane of a PropertySheet -// 2000/08/03 Removed the need for DECLARE_LAYOUT -// -// Version: 1.2 [2000/08/05] - -#define OEMRESOURCE -#include - -#include "stdafx.h" -#include "ETSLayout.h" - -using namespace ETSLayout; -#pragma warning(disable: 4097 4610 4510 4100) - - -#ifndef OBM_SIZE -#define OBM_SIZE 32766 -// taken from WinresRc.h -// if not used for any reason -#endif - -#ifdef _DEBUG -#define new DEBUG_NEW -#undef THIS_FILE -static char THIS_FILE[] = __FILE__; -#endif - -static UINT auIDStatusBar[] = -{ - ID_SEPARATOR -}; - -const int ERASE_GROUP_BORDER = 10; -const int FIXUP_CUTOFF = 5; -const int TAB_SPACE = 5; - -// the _NULL-Pane -CWnd* ETSLayoutMgr::paneNull = 0; - -void ETSLayoutMgr::Layout(CRect& rcClient) -{ - if(rcClient.Height() && rcClient.Width() && m_RootPane.IsValid()) \ - m_RootPane->resizeTo(rcClient); \ -} - - -ETSLayoutMgr::CPane ETSLayoutMgr::pane( layOrientation orientation, ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/, - int sizeBorder /*=nDefaultBorder*/, int sizeExtraBorder /*=0*/, - int sizeSecondary /*=0*/) -{ - Pane* pPane = new Pane ( this, orientation, sizeBorder, sizeExtraBorder ); - pPane->m_sizeSecondary = sizeSecondary; - pPane->m_modeResize = modeResize; - - return CPane(pPane); -} - -ETSLayoutMgr::CPane ETSLayoutMgr::paneTab( CTabCtrl* pTab, layOrientation orientation, - ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/, int sizeBorder /*=nDefaultBorder*/, - int sizeExtraBorder /*=0*/, int sizeSecondary /*=0*/) -{ - Pane* pPane = new PaneTab ( pTab, this, orientation, sizeBorder, sizeExtraBorder ); - pPane->m_sizeSecondary = sizeSecondary; - pPane->m_modeResize = modeResize; - - return CPane(pPane); -} - - -ETSLayoutMgr::CPane ETSLayoutMgr::paneCtrl( CWnd* pCtrl, layOrientation orientation, - ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/, int sizeBorder /*=nDefaultBorder*/, - int sizeExtraBorder /*=0*/, int sizeTopExtra /*=0*/, - int sizeSecondary /*=0*/) -{ - Pane* pPane = new PaneCtrl ( pCtrl, this, orientation, sizeBorder, sizeExtraBorder, sizeTopExtra ); - pPane->m_sizeSecondary = sizeSecondary; - pPane->m_modeResize = modeResize; - - return CPane(pPane); -} - -ETSLayoutMgr::CPane ETSLayoutMgr::paneCtrl( UINT nID, layOrientation orientation, ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/, - int sizeBorder /*=nDefaultBorder*/, int sizeExtraBorder /*=0*/, - int sizeTopExtra /*=0*/, int sizeSecondary /*=0*/) -{ - Pane* pPane = new PaneCtrl ( nID, this, orientation, sizeBorder, sizeExtraBorder, sizeTopExtra ); - pPane->m_sizeSecondary = sizeSecondary; - pPane->m_modeResize = modeResize; - - return CPane(pPane); -} - - -ETSLayoutMgr::CPaneBase ETSLayoutMgr::item(UINT nID, ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/, int sizeX /*=0*/, int sizeY /*=0*/, - int sizeXMin /*=-1*/, int sizeYMin /*=-1*/) -{ - return new PaneItem( nID, this, modeResize, sizeX, sizeY, sizeXMin, sizeYMin); -} - -ETSLayoutMgr::CPaneBase ETSLayoutMgr::item(CWnd* pWnd, ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/, - int sizeX /*=0*/, int sizeY /*=0*/, int sizeXMin /*=-1*/, - int sizeYMin /*=-1*/) -{ - return new PaneItem( pWnd, this, modeResize, sizeX, sizeY, sizeXMin, sizeYMin); -} - -ETSLayoutMgr::CPaneBase ETSLayoutMgr::itemFixed(layOrientation orientation, int sizePrimary) -{ - CPaneBase p = new PaneItem(paneNull, this, NORESIZE, (orientation==HORIZONTAL)?sizePrimary:0, (orientation==VERTICAL)?sizePrimary:0); - return p; -} - -ETSLayoutMgr::CPaneBase ETSLayoutMgr::itemGrowing(layOrientation orientation) -{ - return new PaneItem(paneNull, this, (orientation==HORIZONTAL)?ABSOLUTE_VERT:ABSOLUTE_HORZ, 0, 0, -nDefaultBorder, -nDefaultBorder); -} - -ETSLayoutMgr::CPaneBase ETSLayoutMgr::itemSpaceBetween( layOrientation orientation, CWnd* pWndFirst, CWnd* pWndSecond ) -{ - if( orientation == HORIZONTAL ) { - // I'm interested in horizontal spacing - - CRect rLeft, rRight; - pWndFirst->GetWindowRect(&rLeft); - pWndSecond->GetWindowRect(&rRight); - - int sizeX = rRight.left - rLeft.right; - - if( sizeX < 0 ) { - // compare top to top - sizeX = rRight.left - rLeft.left; - } - else { - sizeX -= 2*nDefaultBorder; - } - - return new PaneItem(paneNull, this, NORESIZE, sizeX, 0); - } - else { - // I'm interested in vertical spacing - CRect rTop, rBot; - pWndFirst->GetWindowRect(&rTop); - pWndSecond->GetWindowRect(&rBot); - - int sizeY = rBot.top - rTop.bottom; - - if( sizeY < 0 ) { - // compare top to top - sizeY = sizeY = rBot.top - rTop.top; - } - else { - sizeY -= 2*nDefaultBorder; - } - - return new PaneItem(paneNull, this, NORESIZE, 0, sizeY); - } -} - - -ETSLayoutMgr::CPaneBase ETSLayoutMgr::itemSpaceBetween( layOrientation orientation, UINT nIDFirst, UINT nIDSecond ) -{ - CWnd *pFirst = GetWnd()->GetDlgItem(nIDFirst); - CWnd *pSecond = GetWnd()->GetDlgItem(nIDSecond); - - ASSERT( pFirst && pSecond ); - - return itemSpaceBetween( orientation, pFirst, pSecond ); -} - - -ETSLayoutMgr::CPaneBase ETSLayoutMgr::itemSpaceLike( layOrientation orientation, CWnd* pWnd ) -{ - CRect rRect; - pWnd->GetWindowRect(&rRect); - - if( orientation == HORIZONTAL ) { - // I'm interested in horizontal spacing - return new PaneItem(paneNull, this, NORESIZE, rRect.Width(), 0); - } - else { - // I'm interested in vertical spacing - return new PaneItem(paneNull, this, NORESIZE, 0, rRect.Height() ); - } - -} - - -ETSLayoutMgr::CPaneBase ETSLayoutMgr::itemSpaceLike( layOrientation orientation, UINT nID ) -{ - CWnd *pWnd = GetWnd()->GetDlgItem(nID); - ASSERT( pWnd ); - - return itemSpaceLike( orientation, pWnd ); -} - - - -ETSLayoutMgr::~ETSLayoutMgr() -{ -} - -void ETSLayoutMgr::UpdateLayout() -{ - if(!m_RootPane) - return; - - // Check constraints - CRect rcClient = GetRect(); - - if( m_pWnd->IsKindOf( RUNTIME_CLASS( CDialog ) ) && !(m_pWnd->GetStyle()&WS_CHILD) ) { - CRect rcWindow; - m_pWnd->GetWindowRect(rcWindow); - - // Added by Didier BULTIAUW - CWnd* parentWnd = m_pWnd->GetParent(); - if( (parentWnd != 0) && parentWnd->IsKindOf(RUNTIME_CLASS(CView)) ) - { - CRect rcParent; - parentWnd->GetWindowRect(rcParent); - rcWindow.OffsetRect(-rcParent.left,-rcParent.top); - } - // end add - - CRect rcBorder = rcWindow; - rcBorder -= rcClient; - - // Min and Max info - int minWidth = m_RootPane->getMinConstrainHorz() + rcBorder.Width() + 2*m_sizeRootBorders.cx; - int minHeight = m_RootPane->getMinConstrainVert() + rcBorder.Height() + 2*m_sizeRootBorders.cy; - int maxWidth = m_RootPane->getMaxConstrainHorz(); - if(maxWidth != -1) { - maxWidth += rcBorder.Width() + 2*m_sizeRootBorders.cx; - maxWidth = max(maxWidth, minWidth); - } - int maxHeight = m_RootPane->getMaxConstrainVert(); - if(maxHeight != -1) { - maxHeight += rcBorder.Height() + 2*m_sizeRootBorders.cy; - maxHeight = max(maxHeight, minHeight); - } - - if(rcWindow.Width() < minWidth) - rcWindow.right = rcWindow.left + minWidth; - if(rcWindow.Height() < minHeight) - rcWindow.bottom = rcWindow.top + minHeight; - - if(maxWidth != -1 && rcWindow.Width() > maxWidth) - rcWindow.right = rcWindow.left + maxWidth; - if(maxHeight != -1 && rcWindow.Height() > maxHeight) - rcWindow.bottom = rcWindow.top + maxHeight; - - m_pWnd->MoveWindow(rcWindow); - } - // Do the Layout - rcClient = GetRect(); - - // Add a Border around the rootPane - rcClient.top += m_sizeRootBorders.cy; - rcClient.bottom -= m_sizeRootBorders.cy; - rcClient.left += m_sizeRootBorders.cx; - rcClient.right -= m_sizeRootBorders.cx; - - if(GetWnd()->IsWindowVisible()) { - // Avoid ugly artifacts - //GetWnd()->SetRedraw(FALSE); - Layout(rcClient); - //GetWnd()->SetRedraw(TRUE); - } - else - Layout(rcClient); - - // Take special care of SpinButtons (Up-Down Controls) with Buddy set, enumerate - // all childs: - CWnd* pWndChild = GetWnd()->GetWindow(GW_CHILD); - TCHAR szClassName[ MAX_PATH ]; - while(pWndChild) - { - ::GetClassName( pWndChild->GetSafeHwnd(), szClassName, MAX_PATH ); - DWORD dwStyle = pWndChild->GetStyle(); - - // is it a SpinButton? - if( _tcscmp(szClassName, UPDOWN_CLASS)==0 && ::IsWindowVisible(pWndChild->GetSafeHwnd()) ) { - HWND hwndBuddy = (HWND)::SendMessage( pWndChild->GetSafeHwnd(), UDM_GETBUDDY, 0, 0); - if( hwndBuddy != 0 && (dwStyle&(UDS_ALIGNRIGHT|UDS_ALIGNLEFT)) != 0 ) - { - // reset Buddy - ::SendMessage( pWndChild->GetSafeHwnd(), UDM_SETBUDDY, (WPARAM)hwndBuddy, 0); - } - } - - - pWndChild = pWndChild->GetWindow(GW_HWNDNEXT); - } - - - GetWnd()->Invalidate(); -} - - -bool ETSLayoutMgr::Save(LPCTSTR lpstrRegKey) -{ - CRect rcWnd; - - if(IsWindow(GetWnd()->m_hWnd)) - { - WINDOWPLACEMENT wp; - if(GetWnd()->GetWindowPlacement(&wp)) - { - // Make sure we don't pop up - // minimized the next time - if(wp.showCmd != SW_SHOWMAXIMIZED) - wp.showCmd = SW_SHOWNORMAL; - - AfxGetApp()->WriteProfileBinary(lpstrRegKey, - _T("WindowPlacement"), - reinterpret_cast(&wp), sizeof(wp)); - } - } - return true; -} - -bool ETSLayoutMgr::Load(LPCTSTR lpstrRegKey) -{ - LPBYTE pbtData = 0; - UINT nSize = 0; - if(AfxGetApp()->GetProfileBinary(lpstrRegKey, - _T("WindowPlacement"), &pbtData, &nSize)) - { - WINDOWPLACEMENT* pwp = - reinterpret_cast(pbtData); - - ASSERT(nSize == sizeof(WINDOWPLACEMENT)); - if(nSize == sizeof(WINDOWPLACEMENT)) - GetWnd()->SetWindowPlacement(reinterpret_cast(pbtData)); - - delete [] pbtData; - } - return true; -} - - -void ETSLayoutMgr::EraseBkgnd(CDC* pDC) -{ - CRect rcClient; - GetWnd()->GetClientRect( rcClient ); - - CRgn rgn; - rgn.CreateRectRgnIndirect(rcClient); - TRACE("CreateRgn (%d,%d,%d,%d)\n", rcClient.left, rcClient.top, rcClient.right, rcClient.bottom ); - - CRgn rgnRect; - rgnRect.CreateRectRgn(0,0,0,0); - - CRect rcChild; - CWnd* pWndChild = GetWnd()->GetWindow( GW_CHILD ); - - TCHAR szClassName[ MAX_PATH ]; - - pDC->SelectClipRgn(NULL); - - while( pWndChild ) { - - pWndChild->GetWindowRect(rcChild); - GetWnd()->ScreenToClient( rcChild ); - - rgnRect.SetRectRgn( rcChild ); - - ::GetClassName( pWndChild->GetSafeHwnd(), szClassName, MAX_PATH ); - DWORD dwStyle = pWndChild->GetStyle(); - - // doesn't make sense for hidden children - if( dwStyle & WS_VISIBLE ) { - - // Fix: BS_GROUPBOX is more than one Bit, extend check to (dwStyle & BS_GROUPBOX)==BS_GROUPBOX [ET] - if( _tcscmp(szClassName,_T("Button"))==0 && (dwStyle & BS_GROUPBOX)==BS_GROUPBOX ) { - // it is a group-box, ignore completely - } - else if( _tcscmp(szClassName,WC_TABCONTROL )==0 ) { - // ignore Tab-Control's inside rect - static_cast(pWndChild)->AdjustRect(FALSE,rcChild); - - CRgn rgnContent; - rgnContent.CreateRectRgnIndirect(rcChild); - - rgnRect.CombineRgn( &rgnRect, &rgnContent, RGN_DIFF ); - rgn.CombineRgn( &rgn, &rgnRect, RGN_DIFF ); - } - else if( _tcscmp(szClassName,STATUSCLASSNAME)==0 ) { - - CPoint ptTriangleGrip[3]; - ptTriangleGrip[0] = CPoint(rcChild.right,rcChild.top); - ptTriangleGrip[1] = CPoint(rcChild.right,rcChild.bottom); - ptTriangleGrip[2] = CPoint(rcChild.right-rcChild.Height(),rcChild.bottom); - - CRgn rgnGripper; - rgnGripper.CreatePolygonRgn(ptTriangleGrip,3, WINDING); - - rgn.CombineRgn( &rgn, &rgnGripper, RGN_DIFF ); - - } - else { - rgn.CombineRgn( &rgn, &rgnRect, RGN_DIFF ); - } - } - - pWndChild = pWndChild->GetNextWindow(); - } - - - HBRUSH hBrBack = (HBRUSH) ::GetClassLong(GetWnd()->GetSafeHwnd(), GCL_HBRBACKGROUND) ; - if( hBrBack == 0 ) - hBrBack = ::GetSysColorBrush(COLOR_BTNFACE); - - pDC->FillRgn( &rgn, - CBrush::FromHandle( hBrBack ) - ); - -} - -///////////////////////////////////////////////////////////////////////////// -// ETSLayoutMgr::PaneItem implementation - - -ETSLayoutMgr::PaneItem::PaneItem(CWnd* pWnd, ETSLayoutMgr* pMgr, ETSLayoutMgr::layResizeMode modeResize/*=GREEDY*/ - , int sizeX/*=0*/, int sizeY/*=0*/ - , int sizeXMin/*=-1*/, int sizeYMin/*=-1*/ ) : PaneBase( pMgr ) -{ - m_modeResize = modeResize; - m_hwndCtrl = pWnd->GetSafeHwnd(); - - m_sizeX = 0; - m_sizeY = 0; - - m_bComboSpecial = false; - - m_sizeXMin = sizeXMin; - m_sizeYMin = sizeYMin; - - if(!m_hwndCtrl) { // only Dummy! - m_sizeX = sizeX; - m_sizeY = sizeY; - } - else { - CRect rcControl; - ::GetWindowRect(m_hwndCtrl, &rcControl); - - if(sizeX == 0) { - m_sizeX = rcControl.Width(); - } - else { - m_sizeX = sizeX; - } - if( m_sizeXMin == -1 ) { - // do not make smaller than current size - m_sizeXMin = rcControl.Width(); - } - - if(sizeY == 0) { - m_sizeY = rcControl.Height(); - } - else { - m_sizeY = sizeY; - } - if( m_sizeYMin == -1 ) { - // do not make smaller than current size - m_sizeYMin = rcControl.Height(); - } - - TCHAR szClassName[ MAX_PATH ]; - ::GetClassName( m_hwndCtrl, szClassName, MAX_PATH ); - - // special treatment for combo-boxes - if( _tcscmp(szClassName,_T("ComboBox"))==0 || _tcscmp(szClassName,WC_COMBOBOXEX)==0) { - m_bComboSpecial = true; - } - } -} - -ETSLayoutMgr::PaneItem::PaneItem( UINT nID, ETSLayoutMgr* pMgr, ETSLayoutMgr::layResizeMode modeResize/*=GREEDY*/ - , int sizeX/*=0*/, int sizeY/*=0*/ - , int sizeXMin/*=-1*/, int sizeYMin/*=-1*/ ) : PaneBase( pMgr ) -{ - CWnd* pWnd = pMgr->GetWnd()->GetDlgItem(nID); - m_hwndCtrl = pWnd->GetSafeHwnd(); - - m_sizeX = 0; - m_sizeY = 0; - - m_bComboSpecial = false; - - m_modeResize = modeResize; - - m_sizeXMin = sizeXMin; - m_sizeYMin = sizeYMin; - - if(!m_hwndCtrl) { // only Dummy! - m_sizeX = sizeX; - m_sizeY = sizeY; - } - else { - CRect rcControl; - ::GetWindowRect(m_hwndCtrl, &rcControl); - - if(sizeX == 0) { - m_sizeX = rcControl.Width(); - } - else { - m_sizeX = sizeX; - } - if( m_sizeXMin == -1 ) { - // do not make smaller than current size - m_sizeXMin = rcControl.Width(); - } - - if(sizeY == 0) { - m_sizeY = rcControl.Height(); - } - else { - m_sizeY = sizeY; - } - if( m_sizeYMin == -1 ) { - // do not make smaller than current size - m_sizeYMin = rcControl.Height(); - } - - TCHAR szClassName[ MAX_PATH ]; - ::GetClassName( m_hwndCtrl, szClassName, MAX_PATH ); - - // special treatment for combo-boxes - if( _tcscmp(szClassName,_T("ComboBox"))==0 || _tcscmp(szClassName,WC_COMBOBOXEX)==0) { - m_bComboSpecial = true; - } - } -} - -int ETSLayoutMgr::PaneItem::getConstrainHorz(int sizeParent) -{ - if( m_modeResize & ABSOLUTE_HORZ) { - return m_sizeX; - } - if(m_modeResize & RELATIVE_HORZ) { - return (sizeParent * m_sizeX) / 100; - } - return -1; -} - -int ETSLayoutMgr::PaneItem::getConstrainVert(int sizeParent) -{ - if(m_modeResize & ABSOLUTE_VERT) { - return m_sizeY; - } - if(m_modeResize & RELATIVE_VERT) { - return (sizeParent * m_sizeY) / 100; - } - return -1; -} - -int ETSLayoutMgr::PaneItem::getMinConstrainHorz() -{ - if(m_modeResize & ABSOLUTE_HORZ) { - return m_sizeX; - } - return max(nMinConstrain,m_sizeXMin); -} - -int ETSLayoutMgr::PaneItem::getMinConstrainVert() -{ - if(m_modeResize & ABSOLUTE_VERT) { - return m_sizeY; - } - return max(nMinConstrain,m_sizeYMin); -} - -int ETSLayoutMgr::PaneItem::getMaxConstrainHorz() -{ - if(m_modeResize & ABSOLUTE_HORZ) { - return m_sizeX; - } - return -1; -} - -int ETSLayoutMgr::PaneItem::getMaxConstrainVert() -{ - if(m_modeResize & ABSOLUTE_VERT) { - return m_sizeY; - } - return -1; -} - -bool ETSLayoutMgr::PaneItem::resizeTo(CRect& rcNewArea) -{ - if(m_hwndCtrl) { - - CRect rcWnd; - ::GetWindowRect( m_hwndCtrl, rcWnd ); - - if( !(m_modeResize & ALIGN_FILL_HORZ) && m_modeResize & ABSOLUTE_HORZ ) { - - - if( (m_modeResize & ALIGN_HCENTER) == ALIGN_HCENTER ) { - rcNewArea.OffsetRect( (rcNewArea.Width() - rcWnd.Width())/2, 0 ); - } - else if( m_modeResize & ALIGN_RIGHT ) { - rcNewArea.OffsetRect( rcNewArea.Width() - rcWnd.Width(), 0 ); - } - - rcNewArea.right = rcNewArea.left + rcWnd.Width(); - } - if( !(m_modeResize & ALIGN_FILL_VERT) && m_modeResize & ABSOLUTE_VERT ) { - - - if( (m_modeResize & ALIGN_VCENTER) == ALIGN_VCENTER ) { - rcNewArea.OffsetRect( 0, (rcNewArea.Height()-rcWnd.Height())/2 ); - } - else if( m_modeResize & ALIGN_BOTTOM ) { - rcNewArea.OffsetRect( 0, rcNewArea.Height() - rcWnd.Height()); - } - - rcNewArea.bottom = rcNewArea.top + rcWnd.Height(); - - } - - DWORD dwStyle = ::GetWindowLong( m_hwndCtrl, GWL_STYLE ); - - // special treatment for combo-boxes - if( m_bComboSpecial && (dwStyle & CBS_DROPDOWN) ) { - // keep height (though only fully visible when dropped down) - rcNewArea.bottom = rcNewArea.top + rcWnd.Height(); - } - - // FIX: ::MoveWindow would case problems with some ActiveX Controls [Micheal Chapman] - CWnd* pTempWnd = CWnd::FromHandle( m_hwndCtrl ); - pTempWnd->MoveWindow( rcNewArea.left, rcNewArea.top, rcNewArea.Width(), rcNewArea.Height() ); - - if( m_bComboSpecial && !(dwStyle & CBS_DROPDOWN) && !(dwStyle & CBS_NOINTEGRALHEIGHT) ) { - - // Keep CB Size = Edit + LB ( if not CBS_NOINTEGRALHEIGHT) - - ::GetWindowRect( m_hwndCtrl, rcWnd ); - - CRect rcListBox; - HWND hwndListBox = ::GetDlgItem(m_hwndCtrl, 1000); // ListBox of CB - if( hwndListBox != 0 ) - { - ::GetWindowRect( hwndListBox, rcListBox ); - rcWnd.bottom = rcListBox.bottom; - - rcNewArea.bottom = rcNewArea.top + rcWnd.Height(); - - // FIX: ::MoveWindow would case problems with some ActiveX Controls [Micheal Chapman] - CWnd* pTempWnd = CWnd::FromHandle( m_hwndCtrl ); - pTempWnd->MoveWindow( rcNewArea.left, rcNewArea.top, rcNewArea.Width(), rcNewArea.Height(), true ); - } - } - - ::RedrawWindow(m_hwndCtrl,0,0, RDW_INVALIDATE | RDW_UPDATENOW ); - - } - return true; -} - - -///////////////////////////////////////////////////////////////////////////// -// ETSLayoutMgr::PaneTab implementation - - -ETSLayoutMgr::PaneTab::PaneTab( CTabCtrl* pTab, ETSLayoutMgr* pMgr, layOrientation orientation, int sizeBorder /*= nDefaultBorder*/, int sizeExtraBorder /*= 0*/ ) -: ETSLayoutMgr::Pane(pMgr, orientation, sizeBorder, sizeExtraBorder) -{ - ASSERT(pTab); - m_pTab = pTab; -} - -int ETSLayoutMgr::PaneTab::getConstrainHorz(int sizeParent) -{ - CRect rcTab; - m_pTab->AdjustRect(TRUE, &rcTab); - - if(rcTab.Width() > sizeParent) - return rcTab.Width(); - - return Pane::getConstrainHorz(sizeParent /*- rcTab.Width()*/); -} - -int ETSLayoutMgr::PaneTab::getConstrainVert(int sizeParent) -{ - CRect rcTab; - m_pTab->AdjustRect(TRUE, &rcTab); - - if( m_modeResize & ABSOLUTE_VERT ) { - return m_sizeSecondary + rcTab.Height(); - } - - if(rcTab.Height() > sizeParent) - return rcTab.Height(); - - return Pane::getConstrainVert(sizeParent /*- rcTab.Height()*/); -} - -int ETSLayoutMgr::PaneTab::getMinConstrainHorz() -{ - CRect rcTab(0,0,0,0); - m_pTab->AdjustRect(TRUE, &rcTab); - - return Pane::getMinConstrainHorz() + rcTab.Width() ; -} - -int ETSLayoutMgr::PaneTab::getMinConstrainVert() -{ - CRect rcTab(0,0,0,0); - m_pTab->AdjustRect(TRUE, &rcTab); - - return Pane::getMinConstrainVert() + rcTab.Height(); -} - -int ETSLayoutMgr::PaneTab::getMaxConstrainHorz() -{ - CRect rcTab(0,0,0,0); - m_pTab->AdjustRect(TRUE, &rcTab); - - int paneMax = Pane::getMaxConstrainHorz(); - return (paneMax != -1) ? paneMax + rcTab.Width() : -1; -} - -int ETSLayoutMgr::PaneTab::getMaxConstrainVert() -{ - CRect rcTab(0,0,0,0); - m_pTab->AdjustRect(TRUE, &rcTab); - - int paneMax = Pane::getMaxConstrainVert(); - return (paneMax != -1) ? paneMax + rcTab.Height() : -1; -} - -bool ETSLayoutMgr::PaneTab::resizeTo(CRect& rcNewArea) -{ - m_pTab->MoveWindow(rcNewArea); - m_pTab->AdjustRect(FALSE,rcNewArea); - - return Pane::resizeTo(rcNewArea); -} - -///////////////////////////////////////////////////////////////////////////// -// ETSLayoutMgr::PaneCtrl implementation - - -ETSLayoutMgr::PaneCtrl::PaneCtrl( CWnd* pCtrl, ETSLayoutMgr* pMgr, layOrientation orientation, int sizeBorder /*= nDefaultBorder*/, int sizeExtraBorder /*= 0*/, int sizeTopExtra /*= 0*/ ) -: ETSLayoutMgr::Pane(pMgr, orientation, sizeBorder, sizeExtraBorder) -{ - m_sizeTopExtra = sizeTopExtra; - - ASSERT(pCtrl); - m_hwndCtrl = pCtrl->GetSafeHwnd(); -} - -ETSLayoutMgr::PaneCtrl::PaneCtrl( UINT nID, ETSLayoutMgr* pMgr, layOrientation orientation, int sizeBorder /*= nDefaultBorder*/, int sizeExtraBorder /*= 0*/, int sizeTopExtra /*= 0*/ ) -: ETSLayoutMgr::Pane(pMgr, orientation, sizeBorder, sizeExtraBorder) -{ - m_sizeTopExtra = sizeTopExtra; - - m_hwndCtrl = ::GetDlgItem(pMgr->GetWnd()->GetSafeHwnd(), nID); - ASSERT(m_hwndCtrl); -} - -int ETSLayoutMgr::PaneCtrl::getConstrainHorz(int sizeParent) -{ - return Pane::getConstrainHorz(sizeParent) ; -} - -int ETSLayoutMgr::PaneCtrl::getConstrainVert(int sizeParent) -{ - return Pane::getConstrainVert(sizeParent); -} - -int ETSLayoutMgr::PaneCtrl::getMinConstrainHorz() -{ - return Pane::getMinConstrainHorz(); -} - -int ETSLayoutMgr::PaneCtrl::getMinConstrainVert() -{ - return Pane::getMinConstrainVert() + m_sizeTopExtra; -} - -int ETSLayoutMgr::PaneCtrl::getMaxConstrainHorz() -{ - int paneMax = Pane::getMaxConstrainHorz(); - return ( paneMax == -1) ? -1 : paneMax ; -} - -int ETSLayoutMgr::PaneCtrl::getMaxConstrainVert() -{ - int paneMax = Pane::getMaxConstrainVert(); - return ( paneMax == -1) ? -1 : paneMax + m_sizeTopExtra; -} - -bool ETSLayoutMgr::PaneCtrl::resizeTo(CRect& rcNewArea) -{ - // FIX: ::MoveWindow would case problems with some ActiveX Controls [Micheal Chapman] - CWnd* pTempWnd = CWnd::FromHandle( m_hwndCtrl ); - pTempWnd->MoveWindow( rcNewArea.left, rcNewArea.top, rcNewArea.Width(), rcNewArea.Height(), true ); - - ::RedrawWindow(m_hwndCtrl,0,0, RDW_INVALIDATE | RDW_UPDATENOW |RDW_ERASE); - rcNewArea.top += m_sizeTopExtra; - return Pane::resizeTo(rcNewArea); -} - -///////////////////////////////////////////////////////////////////////////// -// ETSLayoutMgr::Pane implementation - -ETSLayoutMgr::Pane::Pane( ETSLayoutMgr* pMgr, layOrientation orientation, int sizeBorder /* = nDefaultBorder */, int sizeExtraBorder /*= 0*/) -: PaneBase(pMgr) -{ - m_Orientation = orientation; - m_sizeBorder = sizeBorder; - m_sizeSecondary = 0; - m_modeResize = 0; - m_sizeExtraBorder= sizeExtraBorder; -} - - -ETSLayoutMgr::Pane::~Pane() -{ -} - - -bool ETSLayoutMgr::Pane::addItem( CWnd* pWnd, ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/, int sizeX /*=0*/, int sizeY /*=0*/, int sizeXMin /*=0*/, int sizeYMin /*=0*/) -{ - CPaneBase pItem = new PaneItem( pWnd, m_pMgr, modeResize, sizeX, sizeY, sizeXMin, sizeYMin); - return addPane( pItem ); -} - -bool ETSLayoutMgr::Pane::addItem( UINT nID, ETSLayoutMgr::layResizeMode modeResize /*=GREEDY*/, int sizeX /*=0*/, int sizeY /*=0*/, int sizeXMin /*=0*/, int sizeYMin /*=0*/) -{ - CPaneBase pItem = new PaneItem( nID, m_pMgr, modeResize, sizeX, sizeY, sizeXMin, sizeYMin); - return addPane( pItem ); -} - -bool ETSLayoutMgr::Pane::addItemFixed(int size) -{ - CPaneBase pNewItem = m_pMgr->itemFixed(m_Orientation, size); - return addPane( pNewItem ); -} - -bool ETSLayoutMgr::Pane::addItemGrowing() -{ - CPaneBase pNewItem = m_pMgr->itemGrowing(m_Orientation); - return addPane( pNewItem ); -} - -bool ETSLayoutMgr::Pane::addItemSpaceBetween( CWnd* pWndFirst, CWnd* pWndSecond ) -{ - CPaneBase pNewItem = m_pMgr->itemSpaceBetween(m_Orientation, pWndFirst, pWndSecond); - return addPane( pNewItem ); -} - -bool ETSLayoutMgr::Pane::addItemSpaceBetween( UINT nIDFirst, UINT nIDSecond ) -{ - CPaneBase pNewItem = m_pMgr->itemSpaceBetween(m_Orientation, nIDFirst, nIDSecond); - return addPane( pNewItem ); -} - -bool ETSLayoutMgr::Pane::addItemSpaceLike( CWnd* pWnd ) -{ - CPaneBase pNewItem = m_pMgr->itemSpaceLike(m_Orientation, pWnd); - return addPane( pNewItem ); -} - -bool ETSLayoutMgr::Pane::addItemSpaceLike( UINT nID ) -{ - CPaneBase pNewItem = m_pMgr->itemSpaceLike(m_Orientation, nID); - return addPane( pNewItem ); -} - -bool ETSLayoutMgr::Pane::addPane( CPane pSubpane, ETSLayoutMgr::layResizeMode modeResize, int sizeSecondary /* = 0 */) -{ - if( pSubpane->getOrientation() == m_Orientation) - { - // wrap in subpane of opposite orientation - CPane pPaneWrap = new Pane(m_pMgr, m_Orientation==HORIZONTAL?VERTICAL:HORIZONTAL,0,0); - pPaneWrap->addPane( pSubpane ); - - addPane( pPaneWrap, modeResize, sizeSecondary ); - } - else - { - pSubpane->m_modeResize = modeResize; - - if(m_Orientation==HORIZONTAL && (modeResize & ABSOLUTE_HORZ) ) { - if(sizeSecondary == 0) { - pSubpane->m_sizeSecondary = pSubpane->getMinConstrainHorz(); - } - } - else if(m_Orientation==HORIZONTAL && (modeResize & RELATIVE_HORZ) ) { - pSubpane->m_sizeSecondary = sizeSecondary; - } - else if(m_Orientation==VERTICAL && (modeResize & ABSOLUTE_VERT) ) { - if(sizeSecondary == 0) { - pSubpane->m_sizeSecondary = pSubpane->getMinConstrainVert(); - } - } - else if(m_Orientation==VERTICAL && (modeResize & RELATIVE_VERT) ) { - pSubpane->m_sizeSecondary = sizeSecondary; - } - - m_paneItems.Add(pSubpane); - } - - return true; -} - -bool ETSLayoutMgr::Pane::addPane( CPaneBase pItem ) -{ - m_paneItems.Add(pItem); - return true; -} - -int ETSLayoutMgr::Pane::getConstrainHorz(int sizeParent) -{ - ASSERT( m_Orientation == VERTICAL); - - if( m_modeResize & RELATIVE_HORZ ) { - return (sizeParent * m_sizeSecondary) / 100; - } - else if( m_modeResize & ABSOLUTE_HORZ ){ - return m_sizeSecondary; - } - else - return 0; -} - - -int ETSLayoutMgr::Pane::getConstrainVert(int sizeParent) -{ - ASSERT( m_Orientation == HORIZONTAL); - - if( m_modeResize & RELATIVE_VERT ) { - return (sizeParent * m_sizeSecondary) / 100; - } - else if( m_modeResize & ABSOLUTE_VERT ) { - return m_sizeSecondary; - } - else { - return 0; - } -} - -int ETSLayoutMgr::Pane::getMaxConstrainHorz() -{ - if(m_Orientation == HORIZONTAL) { - int nMaxConstr = -1; - for(int i=0; igetMaxConstrainHorz(); - if(nConstrain == -1) - return -1; - - nMaxConstr += nConstrain; - } - return (nMaxConstr == -1) ? -1 : nMaxConstr + (m_paneItems.GetUpperBound()*m_sizeBorder) + 2*m_sizeExtraBorder; - } - else if( m_modeResize & ABSOLUTE_HORZ && m_sizeSecondary!=0) { - return m_sizeSecondary; // + 2*m_sizeExtraBorder; - } - else { - int nMaxConstr = -1; - for(int i=0; igetMaxConstrainHorz(); - - if( nConstrain == -1) - return -1; - else - nMaxConstr = max(nMaxConstr, nConstrain); - - } - return (nMaxConstr == -1) ? -1 : nMaxConstr + 2*m_sizeExtraBorder; - } -} - -int ETSLayoutMgr::Pane::getMaxConstrainVert() -{ - if(m_Orientation == VERTICAL) { - int nMaxConstr = -1; - for(int i=0; igetMaxConstrainVert(); - if(nConstrain == -1) - return -1; - - nMaxConstr += nConstrain; - } - return (nMaxConstr == -1) ? -1 : nMaxConstr + (m_paneItems.GetUpperBound()*m_sizeBorder) + 2*m_sizeExtraBorder; - } - else if( m_modeResize & ABSOLUTE_VERT && m_sizeSecondary!=0) { - return m_sizeSecondary; // + 2*m_sizeExtraBorder; - } - else { - int nMaxConstr = -1; - for(int i=0; igetMaxConstrainVert(); - - if( nConstrain == -1) - return -1; - else - nMaxConstr = max(nMaxConstr, nConstrain); - - } - return (nMaxConstr == -1) ? -1 : nMaxConstr + 2*m_sizeExtraBorder; - } -} - -int ETSLayoutMgr::Pane::getMinConstrainHorz() -{ - if(m_Orientation == HORIZONTAL) { - int nMaxConstr = 0; - for(int i=0; igetMinConstrainHorz()); - } - return nMaxConstr + (m_paneItems.GetUpperBound()*m_sizeBorder) + 2*m_sizeExtraBorder; - } - else if( m_modeResize & ABSOLUTE_HORZ && m_sizeSecondary!=0) { - return m_sizeSecondary; // + 2*m_sizeExtraBorder; - } - else { - int nMaxConstr = 0; - for(int i=0; igetMinConstrainHorz(); - nMaxConstr = max(nMaxConstr, nConstrain); - } - return nMaxConstr + 2*m_sizeExtraBorder; - } -} - -int ETSLayoutMgr::Pane::getMinConstrainVert() -{ - if(m_Orientation == VERTICAL) { - int nMaxConstr = 0; - for(int i=0; igetMinConstrainVert()); - } - return nMaxConstr + (m_paneItems.GetUpperBound()*m_sizeBorder) + 2*m_sizeExtraBorder; - } - else if( m_modeResize & ABSOLUTE_VERT && m_sizeSecondary!=0) { - return m_sizeSecondary; // + 2*m_sizeExtraBorder; - } - else { - int nMaxConstr = 0; - for(int i=0; igetMinConstrainVert(); - nMaxConstr = max(nMaxConstr, nConstrain); - } - return nMaxConstr + 2*m_sizeExtraBorder; - } -} - - -int ETSLayoutMgr::Pane::resizeToAbsolute(int& availSpace, CArray& sizePrimary, - CArray& sizeMin, CArray& sizeMax) -{ - // count all greedy items as returnvalue - int nGreedy = 0; - - // first, subtract all absoulute items from available space - for(int i=0; imodeResize() & ABSOLUTE_HORZ) { - availSpace -= (sizePrimary[i] = pItem->getConstrainHorz(0)); - } - - // count Greedy items for later - if(!(pItem->modeResize() & ABSOLUTE_HORZ) && !(pItem->modeResize() & RELATIVE_HORZ)) { - nGreedy++; - } - - sizeMin[i] = pItem->getMinConstrainHorz(); - sizeMax[i] = pItem->getMaxConstrainHorz(); - } - else { - - // for absolute items subtract their size from available space - if(pItem->modeResize() & ABSOLUTE_VERT) { - availSpace -= (sizePrimary[i] = pItem->getConstrainVert(0)); - } - - // count Greedy items for later - if(!(pItem->modeResize() & ABSOLUTE_VERT) && !(pItem->modeResize() & RELATIVE_VERT)) { - nGreedy++; - } - - sizeMin[i] = pItem->getMinConstrainVert(); - sizeMax[i] = pItem->getMaxConstrainVert(); - } - - } - - // Must not be negative !! - availSpace = max(availSpace, 0); - - return nGreedy; -} - -bool ETSLayoutMgr::Pane::resizeToRelative(int& availSpace, CArray& sizePrimary, - CArray& sizeMin, CArray& sizeMax) -{ - // Then all relative items as percentage of left space (as of now after - // all absolute items are subtracted - - int availRel = availSpace; // At the beginning all of remaining space is available. We want all - // operation to be relative to the left space at this moment, so we - // save this amount here. Then we safly can lower availSpace - - int relDiff = 0; // The cumulated difference between first proposed size and - // eventual maximum/minimum size. This amount has to be - // saved in some other place (i.e. where relativ items/subpane - // are not limited by min/max - - int relLeft = 0; // The cumulated amout of space that can be saved by - // shrinking the items/panes up to the minimum - - int relCount = 0; // Actually allocated item/subpane's cumulated primary sizes - // of non-limited items/subpanes (these can be modified in fixup) - // needed for equally distribution of differences amoung non-limited - // relative items/subpanes - - for(int i=0; imodeResize() & RELATIVE_HORZ) - || - (m_Orientation==VERTICAL && pItem->modeResize() & RELATIVE_VERT) ) - { - // minimum item/subpane size in primary direction (pixels) - int nSizeRelMin = sizeMin[i]; - - // maximum item/subpane size in primary direction (pixels) - int nSizeRelMax = sizeMax[i]; - - // Relative size in primary direction (pixels) - int nSizeRel = (m_Orientation==HORIZONTAL) - ? - (pItem->getConstrainHorz(availRel)) - : - (pItem->getConstrainVert(availRel)); - - if( nSizeRel < nSizeRelMin) { - // The item/pane is shrinked too small! - // We will grow it to it's minimum-size. In order not to modify - // this item later when fixing up set the size to the negative - // minimum size - sizePrimary[i] = -nSizeRelMin; - - // As we grew one item/subpane we have to shrink another one. - // We keep count on how much space we needed to grow the item - // to it's minimum size - relDiff += ( nSizeRelMin - nSizeRel ); - } - else if( nSizeRelMax != -1 && nSizeRel > nSizeRelMax) { - // if there's a maximum size (nSizeRelMax != -1) and our item/subpane - // is to be resized over that amount correct it. In order not to modify - // this item later when fixing up set the size to the negative - // maximum size - sizePrimary[i] = -nSizeRelMax; - - // As we shrinked one item/subpane we have to grow another one. - // We keep count on how much space we needed to grow the item - // to it's maximum size. - relDiff += ( nSizeRelMax - nSizeRel ); - } - else { - // this is the normal case: neither are we minimum limited nor maximum - // limited - - // As this item/subpane is larger that it's minimum we could later (if - // necessary for fixup) shrink it for the difference amount of pixels - relLeft += ( nSizeRel - nSizeRelMin ); - - // Set the primary size of this item/pane. Can later be modified by fixup - sizePrimary[i] = nSizeRel; - - // Add this item/subpane's primary size to the count of already allocated - // cumulated size of non-limited items/subpanes (these can be modified in fixup) - relCount += nSizeRel; - } - - // decrease available space by used space in this step - availSpace -= nSizeRel; - } - } - - // We now have the situation that some items/subpanes had to be adjusted for cumulated - // relDiff pixels (positive value means more space taken than indicated by percentage of - // left space). On the other hand we have some items/subpanes which were not limited (in - // their current dimensions) but could be if necessary up to relLeft pixels. - if(relLeft < relDiff && availSpace >= (relDiff-relLeft) ){ - - // If it's not possible to shrink other (relative) panes in order to distribute the - // difference because the left for shrinking (relLeft) is too small we need to aquire - // more space from the globally left space (if available at all) - availSpace -= (relDiff-relLeft); - relDiff = relLeft; - } - - // At this point we should have some space left (at least not be negative with the leftover - // space) and on the other hand there's enough space for the limit-difference to be distributed -// ASSERT( availSpace >= 0 && relLeft >= relDiff); - - // Fixup Relative: - // Distribute (if anecessary) relDiff on other (not limited) relative items/subpanes - // (if available - if not later just grow the limited panes) - while( relDiff != 0 && relCount >= 0 ) { - - // in every iteration there must be some space distributed (of the difference) or it could - // come to endless looping. Save the amount of space actually distributed in this iteration - int relDist = 0; - - for(int i=0; imodeResize() & RELATIVE_HORZ) && sizePrimary[i] > 0) - || - (m_Orientation==VERTICAL && (pItem->modeResize() & RELATIVE_VERT) && sizePrimary[i] > 0) ) - { - // keep a flag for termination of this iteration - bool bLast = false; - - // the difference should be distributed amoung all non-limited items/subpanes equally. - // nDiff is the amount for the current item/subpane - int nDiff = (relDiff * sizePrimary[i]) / relCount; - - // if it's a too small value just add it to the current pane and break iteration - if( abs(relDiff) <= FIXUP_CUTOFF ) { - // take it all in this step - nDiff = relDiff; - - // set break flag - bLast = true; - } - - // calculate the new size for the current item/subpane - int nNewSize = sizePrimary[i] - nDiff; - - if( nNewSize < sizeMin[i] ) { - // oh, we are limited here. Revise our plan: - - // Not all of the space could be saved, add the actually possible space - // to the sum - relDist += ( sizePrimary[i] - sizeMin[i] ); - - // set it to the minimum possible size - sizePrimary[i] = -sizeMin[i]; - - // as this item/subpane is now limited it's occupied space doesn't count - // for relCount anymore - relCount-= ( sizePrimary[i] ); - } - else { - // account the difference of the sizes in relDist and set new size - relDist += ( sizePrimary[i] - nNewSize ); - sizePrimary[i] = nNewSize; - - // if it's the last one break now - if(bLast) - break; - } - } - } - // Distributed some relDiff-space in every iteration -// ASSERT(relDist != 0); - relDiff -= relDist; - - if( relDist == 0 ) - break; - } - - { - // Fixup Relative: invert all negative (limited) sized to correct value - for(int i=0; imodeResize() & RELATIVE_HORZ) && sizePrimary[i] < 0) - || - (m_Orientation==VERTICAL && (pItem->modeResize() & RELATIVE_VERT) && sizePrimary[i] < 0) ) - { - sizePrimary[i] *= -1; - } - } - } - - return true; -} - -bool ETSLayoutMgr::Pane::resizeToGreedy(int& availSpace, int nGreedy, CArray& sizePrimary, - CArray& sizeMin, CArray& sizeMax) -{ - // Now resize all Greedy items/subpanes equally among the remaining space - int greedyDiff = 0; // The cumulated difference between first proposed size and - // eventual maximum/minimum size. This amount has to be - // saved in some other place (i.e. where items/subpane - // are not limited by min/max - - int greedyLeft = 0; // The cumulated amount of space that can be saved by - // shrinking the items/panes up to the minimum - - int greedyCount = 0; // Actually allocated item/subpane's cumulated primary sizes - // of non-limited items/subpanes (these can be modified in fixup) - // needed for equally distribution of differences amoung non-limited - // items/subpanes - - for(int i=0; imodeResize()&ABSOLUTE_HORZ) - && !(pItem->modeResize()&RELATIVE_HORZ) - ) - || - (m_Orientation==VERTICAL - && !(pItem->modeResize()&ABSOLUTE_VERT) - && !(pItem->modeResize()&RELATIVE_VERT) - ) - ) - { - - // All greedy items get an equal portion of the left space - int nSize = availSpace / nGreedy; - - // minimum item/subpane size in primary direction (pixels) - int nSizeMin = sizeMin[i]; - - // maximum item/subpane size in primary direction (pixels) - int nSizeMax = sizeMax[i]; - - - // the last gets the all of the remaining space - if( nGreedy == 1 ) - nSize = availSpace; - - if( nSize < nSizeMin) { - // The item/pane is shrinked too small! - // We will grow it to it's minimum-size. In order not to modify - // this item later when fixing up set the size to the negative - // minimum size - sizePrimary[i] = -nSizeMin; - - // As we grew one item/subpane we have to shrink another one. - // We keep count on how much space we needed to grow the item - // to it's minimum size - greedyDiff += ( nSizeMin - nSize ); - } - else if( nSizeMax != -1 && nSize > nSizeMax) { - // if there's a maximum size (nSizeRelMax != -1) and our item/subpane - // is to be resized over that amount correct it. In order not to modify - // this item later when fixing up set the size to the negative - // maximum size - sizePrimary[i] = -nSizeMax; - - // As we shrinked one item/subpane we have to grow another one. - // We keep count on how much space we needed to grow the item - // to it's maximum size. - greedyDiff += ( nSizeMax - nSize ); - } - else { - - // this is the normal case: neither are we minimum limited nor maximum - // limited - - // As this item/subpane is larger that it's minimum we could later (if - // necessary for fixup) shrink it for the difference amount of pixels - greedyLeft += ( nSize - nSizeMin ); - - // Set the primary size of this item/pane. Can later be modified by fixup - sizePrimary[i] = nSize; - - // Add this item/subpane's primary size to the count of already allocated - // cumulated size of non-limited items/subpanes (these can be modified in fixup) - greedyCount += nSize; - } - - // decrease available space by used space in this step - availSpace -= nSize; - - // one greedy item/subpane complete - --nGreedy; - } - } - - - // Fixup Greedy I - // Distribute (if anecessary) greedyDiff on other (not limited) greedy items/subpanes - // (if available - if not later just grow the limited panes) - - // at least on not limited item present - bool bAtLeastOne = true; - - while( bAtLeastOne && greedyDiff != 0 && greedyCount > 0) { - - // in every iteration there must be some space distributed (of the difference) or it could - // come to endless looping. Save the amount of space actually distributed in this iteration - int greedyDist = 0; - - // at least on not limited item present - bAtLeastOne = false; - - for(int i=0; imodeResize()&ABSOLUTE_HORZ) - && !(pItem->modeResize()&RELATIVE_HORZ) - && sizePrimary[i] > 0 - ) - || - (m_Orientation==VERTICAL - && !(pItem->modeResize()&ABSOLUTE_VERT) - && !(pItem->modeResize()&RELATIVE_VERT) - && sizePrimary[i] > 0 - ) - ) - { - // keep a flag for termination of this iteration - bool bLast = false; - - // the difference should be distributed among all non-limited items/subpanes equally. - // nDiff is the amount for the current item/subpane - int nDiff = (greedyDiff * sizePrimary[i]) / greedyCount; - - // if it's a too small value just add it to the current pane and break iteration - if( abs(greedyDiff) <= FIXUP_CUTOFF || nDiff == 0) { - // take it all in this step - nDiff = greedyDiff; - - // set break flag - bLast = true; - } - - // calculate the new size for the current item/subpane - int nNewSize = sizePrimary[i] - nDiff; - - if( nNewSize < sizeMin[i] ) { - // oh, we are limited here. Revise our plan: - - if( sizePrimary[i] != sizeMin[i] ) - bAtLeastOne = true; - - // Not all of the space could be saved, add the actually possible space - // to the sum - greedyDist += ( sizePrimary[i] - sizeMin[i] ); - - // set it to the minimum possible size - sizePrimary[i] = sizeMin[i]; - - // as this item/subpane is now limited its occupied space doesn't count - // for relCount anymore - greedyCount -= ( sizePrimary[i] ); - } - else { - // yes, there is one - bAtLeastOne = true; - - // account the difference of the sizes in relDist and set new size - greedyDist += ( sizePrimary[i] - nNewSize ); - sizePrimary[i] = nNewSize; - - // if it's the last one break now - if(bLast) - break; - } - } - } - // Distributed some greedyDiff-space in every iteration - ASSERT(!bAtLeastOne || greedyDist != 0 || greedyCount<=0); - greedyDiff -= greedyDist; - } - - - // Fixup Greedy II - if( greedyDiff < 0 ) { - // still difference, some space left - - // are there any items which are minimum-limited where we can give more space? - for(int i=0; imodeResize()&ABSOLUTE_HORZ) - && !(pItem->modeResize()&RELATIVE_HORZ) - ) - || - (m_Orientation==VERTICAL - && !(pItem->modeResize()&ABSOLUTE_VERT) - && !(pItem->modeResize()&RELATIVE_VERT) - ) - ) - { - if( sizePrimary[i] == -sizeMin[i] ) { - // fill this one up as much as possible - if( sizeMax[i] == -1) { - // all fits in - sizePrimary[i] += greedyDiff; - greedyDiff = 0; - } - else { - sizePrimary[i] += -min( -greedyDiff, sizeMax[i]-sizeMin[i]); - greedyDiff -= -min( -greedyDiff, sizeMax[i]-sizeMin[i]); - } - } - } - } - } - - { - // Fixup Greedy III: invert all negative (limited) sized to correct value - for(int i=0; imodeResize() & ABSOLUTE_HORZ) - && !(pItem->modeResize() & RELATIVE_HORZ) - && sizePrimary[i] < 0 - && sizeMin[i] >= 0 - ) - || - (m_Orientation==VERTICAL - && !(pItem->modeResize() & ABSOLUTE_VERT) - && !(pItem->modeResize() & RELATIVE_VERT) - && sizePrimary[i] < 0 - && sizeMin[i] >= 0 - ) - ) - { - if(sizePrimary[i] < 0) - sizePrimary[i] *= -1; - } - } - } - - return true; -} - - -bool ETSLayoutMgr::Pane::resizeTo(CRect& rcNewArea) -{ - // There must be some items or subpanes - ASSERT(m_paneItems.GetSize()); - - // This Array holds the size in primary direction for each item/subpane - CArray sizePrimary; - sizePrimary.SetSize(m_paneItems.GetSize()); - - // This Array holds information about the minimum size in primary direction - CArray sizeMin; - sizeMin.SetSize(m_paneItems.GetSize()); - - // This Array holds information about the maximum size in primary direction - CArray sizeMax; - sizeMax.SetSize(m_paneItems.GetSize()); - - - // How much space is actually available, subtract all borders between items - int availSpace = (m_Orientation == HORIZONTAL ? rcNewArea.Width() : rcNewArea.Height() ) - (m_paneItems.GetUpperBound()*m_sizeBorder); - - // If there is some Extra border (on top/bottem resp. left/right) subtract it too - availSpace -= 2*m_sizeExtraBorder; - - // Add the extra Border to top/bottem resp. left/right - if(m_Orientation == HORIZONTAL) { - rcNewArea.top += m_sizeExtraBorder; - rcNewArea.bottom -= m_sizeExtraBorder; - } - else { - rcNewArea.left += m_sizeExtraBorder; - rcNewArea.right -= m_sizeExtraBorder; - } - - // Counts the number of greedy items/subpanes - int nGreedy = resizeToAbsolute(availSpace, sizePrimary, sizeMin, sizeMax ); - - if(nGreedy == -1) - return false; - - if(! resizeToRelative(availSpace, sizePrimary, sizeMin, sizeMax ) ) - return false; - - if(! resizeToGreedy(availSpace, nGreedy, sizePrimary, sizeMin, sizeMax ) ) - return false; - - - // If there is any left space and there are ALIGN_FILL_* Items to assign it - // equally among them - if( availSpace > 0 ) { - // Count possible Items - int nFillItems = 0; - - for(int i=0; imodeResize() & ABSOLUTE_HORZ ) - && (pItem->modeResize() & ALIGN_FILL_HORZ) - - || - - (pItem->modeResize() & ABSOLUTE_VERT ) - && (pItem->modeResize() & ALIGN_FILL_VERT) - ) - { - ++nFillItems; - } - } - - if( nFillItems > 0 ) { - // okay, there are nFillItems, make them all availSpace/nFillItems bigger - for(int i=0; imodeResize() & ABSOLUTE_HORZ ) - && (pItem->modeResize() & ALIGN_FILL_HORZ) - - || - - (pItem->modeResize() & ABSOLUTE_VERT ) - && (pItem->modeResize() & ALIGN_FILL_VERT) - ) - { - - if( nFillItems == 1 ) { - // the last one gets all the rest - sizePrimary[i] += availSpace; - availSpace = 0; - --nFillItems; - } - else { - sizePrimary[i] += availSpace/nFillItems; - availSpace -= availSpace/nFillItems; - --nFillItems; - } - - } - } - } - - } - - // Now reposition all items: - - // starting offset - int nOffset = (m_Orientation==HORIZONTAL ? rcNewArea.left : rcNewArea.top ) + m_sizeExtraBorder; - for(int i=0; iresizeTo( rcPane ); - - // go to the next position (old pos + size + border) - ASSERT(sizePrimary[i] >= 0); - nOffset += m_sizeBorder + sizePrimary[i]; - } - - - return true; -} - - -///////////////////////////////////////////////////////////////////////////// -// ETSLayoutDialog dialog - -#pragma warning(disable: 4355) -ETSLayoutDialog::ETSLayoutDialog(UINT nID, CWnd* pParent /*=NULL*/, LPCTSTR strName /*=NULL*/, bool bGripper /*=true*/) - : CBaseDialog(nID, pParent), ETSLayoutMgr( this ) -{ - //{{AFX_DATA_INIT(ETSLayoutDialog) - // NOTE: the ClassWizard will add member initialization here - //}}AFX_DATA_INIT - m_bGripper = bGripper; - - if(strName) - m_strRegStore = strName; -} -#pragma warning(default: 4355) - -BEGIN_MESSAGE_MAP(ETSLayoutDialog, CBaseDialog) - //{{AFX_MSG_MAP(ETSLayoutDialog) - ON_WM_SIZE() - ON_WM_GETMINMAXINFO() - ON_WM_ERASEBKGND() - ON_WM_DESTROY() - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - - -///////////////////////////////////////////////////////////////////////////// -// ETSLayoutDialog message handlers - -BOOL ETSLayoutDialog::OnEraseBkgnd(CDC* pDC) -{ - EraseBkgnd(pDC); - return true; -} - -void ETSLayoutDialog::OnSize(UINT nType, int cx, int cy) -{ - CBaseDialog::OnSize(nType, cx, cy); - - if( abs(cx) + abs(cy) > 0) - { - // Reposition Size Marker - // Re-Layout all controls - UpdateLayout(); - RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0); - } - -} - -void ETSLayoutDialog::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) -{ - if(m_RootPane.IsValid()) { - - CRect rcClient = GetRect(); - if( rcClient.Height() > 0 || rcClient.Width() > 0 ) - { - - CRect rcWnd; - GetWindowRect(rcWnd); - - // How much do Window and Client differ - int nDiffHorz = rcWnd.Width() - rcClient.Width(); - int nDiffVert = rcWnd.Height() - rcClient.Height(); - - // Take into account that there is a border around the rootPane - lpMMI->ptMinTrackSize = CPoint(m_RootPane->getMinConstrainHorz() + nDiffHorz + 2*m_sizeRootBorders.cx, - m_RootPane->getMinConstrainVert() + nDiffVert + 2*m_sizeRootBorders.cy); - - int maxWidth = m_RootPane->getMaxConstrainHorz(); - int maxHeight = m_RootPane->getMaxConstrainVert(); - - if( maxWidth != -1 ) { - lpMMI->ptMaxTrackSize.x = maxWidth + nDiffHorz + 2*m_sizeRootBorders.cx; - lpMMI->ptMaxSize.x = maxWidth + nDiffHorz + 2*m_sizeRootBorders.cx; - } - - if( maxHeight != -1 ) { - lpMMI->ptMaxTrackSize.y = maxHeight + nDiffVert + 2*m_sizeRootBorders.cy; - lpMMI->ptMaxSize.y = maxHeight + nDiffVert + 2*m_sizeRootBorders.cy; - } - } - } -} - - -CRect ETSLayoutDialog::GetRect() -{ - CRect r; - GetClientRect(r); - - if( m_bGripper ) - { - if( ::IsWindow(m_StatusBar.GetSafeHwnd()) ) - { - CRect rcSizeIcon; - m_StatusBar.GetWindowRect( rcSizeIcon); - r.bottom -= (rcSizeIcon.Height() - m_sizeRootBorders.cy - 5); - } - } - - return r; -} - - -BOOL ETSLayoutDialog::OnInitDialog() -{ - CBaseDialog::OnInitDialog(); - - // Ensure that the dialog is resizable - this->ModifyStyle(0, WS_THICKFRAME); - - if(!m_strRegStore.IsEmpty()) { - Load(m_strRegStore); - } - -#ifdef _AUTO_SET_ICON - POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition(); - if(pos) { - - class ETSPseudoDocTemplate : public CDocTemplate - { - friend class ETSLayoutDialog; - }; - - ETSPseudoDocTemplate* pDocT = (ETSPseudoDocTemplate*) AfxGetApp()->GetNextDocTemplate(pos); - SetIcon( AfxGetApp()->LoadIcon(pDocT->m_nIDResource) ,FALSE); - } -#endif - - // Sizing icon - if(m_bGripper) - { - if(m_StatusBar.Create(m_pWnd)) - { - m_StatusBar.SetIndicators(auIDStatusBar, sizeof(auIDStatusBar) / sizeof(UINT)); - m_StatusBar.SetWindowText(_T("")); - m_StatusBar.SetPaneStyle( 0, SBPS_STRETCH | SBPS_NOBORDERS ); - m_pWnd -> RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0); - } - else - AfxMessageBox(_T("Error - Statusbar")); - - } - return TRUE; // return TRUE unless you set the focus to a control - // EXCEPTION: OCX Property Pages should return FALSE -} - -void ETSLayoutDialog::OnDestroy() -{ - // Store size/position - if(!m_strRegStore.IsEmpty()) { - Save(m_strRegStore); - } - - // manually delete layout definition if object is reused - m_RootPane = 0; - - CBaseDialog::OnDestroy(); -} - -///////////////////////////////////////////////////////////////////////////// -// ETSLayoutDialog dialog - -#pragma warning(disable: 4355) -#ifdef CS_HELP -ETSLayoutDialogBar::ETSLayoutDialogBar(UINT nID ) - : CBaseDialogBar( nID ), ETSLayoutMgr( this ) -#else -ETSLayoutDialogBar::ETSLayoutDialogBar() - : ETSLayoutMgr( this ) -#endif -{ - //{{AFX_DATA_INIT(ETSLayoutDialogBar) - // NOTE: the ClassWizard will add member initialization here - //}}AFX_DATA_INIT - m_bInitialized = false; - setRootBorders(0,0); -} -#pragma warning(default: 4355) - -BEGIN_MESSAGE_MAP(ETSLayoutDialogBar, CBaseDialogBar) - //{{AFX_MSG_MAP(ETSLayoutDialogBar) - ON_WM_SIZE() - ON_WM_GETMINMAXINFO() - ON_WM_DESTROY() - ON_WM_ERASEBKGND() - ON_MESSAGE(WM_INITDIALOG, OnInitDialog) - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - - -///////////////////////////////////////////////////////////////////////////// -// ETSLayoutDialogBar message handlers - -LRESULT ETSLayoutDialogBar::OnInitDialog(WPARAM, LPARAM) -{ - Default(); - Initialize(); - return TRUE; -} - -void ETSLayoutDialogBar::UpdateLayout() -{ - ETSLayoutMgr::UpdateLayout(); - - if(m_RootPane.IsValid()) { - CRect rcClient = GetRect(); - - CRect rcWnd; - GetWindowRect(rcWnd); - - // How much do Window and Client differ - CSize sizeDiff( rcWnd.Width() - rcClient.Width(), rcWnd.Height() - rcClient.Height()); - - // Take into account that there is a border around the rootPane -// m_szMin = CSize(m_RootPane->getMinConstrainHorz() + sizeDiff.cx + 2*m_sizeRootBorders.cx, -// m_RootPane->getMinConstrainVert() + sizeDiff.cy + 2*m_sizeRootBorders.cy); - } -} - -CSize ETSLayoutDialogBar::CalcDynamicLayout(int nLength, DWORD dwMode) -{ - CSize sizeRet = CBaseDialogBar::CalcDynamicLayout(nLength, dwMode); - - CSize sizeMin = sizeRet; - CSize sizeMax = sizeRet; - - if(m_RootPane.IsValid()) { - CRect rcClient = GetRect(); - - CRect rcWnd; - GetWindowRect(rcWnd); - - // How much do Window and Client differ - CSize sizeDiff( rcWnd.Width() - rcClient.Width(), rcWnd.Height() - rcClient.Height()); - - // Take into account that there is a border around the rootPane -// sizeMin = CSize(m_RootPane->getMinConstrainHorz() + sizeDiff.cx + 2*m_sizeRootBorders.cx, -// m_RootPane->getMinConstrainVert() + sizeDiff.cy + 2*m_sizeRootBorders.cy); - - - int maxWidth = m_RootPane->getMaxConstrainHorz(); - int maxHeight = m_RootPane->getMaxConstrainVert(); - - if( maxWidth != -1 ) { - sizeMax.cx = maxWidth + sizeDiff.cy + 2*m_sizeRootBorders.cx; - } - - if( maxHeight != -1 ) { - sizeMax.cy = maxHeight + sizeDiff.cy + 2*m_sizeRootBorders.cy; - } - } - - if( IsFloating() || !(dwMode&LM_HORZ)) - { - sizeRet.cx = min( sizeRet.cx, sizeMax.cx ); - } - if( IsFloating() || (dwMode&LM_HORZ)) - { - sizeRet.cy = min( sizeRet.cy, sizeMax.cy ); - } - - sizeRet.cx = max( sizeRet.cx, sizeMin.cx ); - sizeRet.cy = max( sizeRet.cy, sizeMin.cy ); - - return sizeRet; -} - -BOOL ETSLayoutDialogBar::OnEraseBkgnd(CDC* pDC) -{ - EraseBkgnd(pDC); - return true; -} - - -void ETSLayoutDialogBar::OnSize(UINT nType, int cx, int cy) -{ - CBaseDialogBar::OnSize(nType, cx, cy); - - if( abs(cx) + abs(cy) > 0) - { - // Re-Layout all controls - UpdateLayout(); - } - RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0); - -} - - -CRect ETSLayoutDialogBar::GetRect() -{ - CRect r; - GetClientRect(r); - - if( IsFloating() ) - r.DeflateRect(4,4); - - return r; -} - - -void ETSLayoutDialogBar::OnDestroy() -{ - // Store size/position on your own! - CBaseDialogBar::OnDestroy(); -} - - - -///////////////////////////////////////////////////////////////////////////// -// ETSLayoutFormView dialog - -IMPLEMENT_DYNAMIC(ETSLayoutFormView, CFormView) - -#pragma warning(disable: 4355) -ETSLayoutFormView::ETSLayoutFormView(UINT nID, LPCTSTR strName /*=NULL*/) - : CBaseFormView(nID), ETSLayoutMgr( this ) -{ - if(strName) - m_strRegStore = strName; -} -#pragma warning(default: 4355) - -BEGIN_MESSAGE_MAP(ETSLayoutFormView, CBaseFormView) - //{{AFX_MSG_MAP(ETSLayoutFormView) - ON_WM_SIZE() - ON_WM_GETMINMAXINFO() - ON_WM_ERASEBKGND() - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - - -///////////////////////////////////////////////////////////////////////////// -// ETSLayoutFormView message handlers - -BOOL ETSLayoutFormView::OnEraseBkgnd(CDC* pDC) -{ - EraseBkgnd(pDC); - return true; -} - - -void ETSLayoutFormView::OnSize(UINT nType, int cx, int cy) -{ -// CBaseFormView::OnSize(nType, cx, cy); - SetScrollSizes(MM_TEXT, CSize(cx,cy)); - if( abs(cx) + abs(cy) > 0) { - // Re-Layout all controls - UpdateLayout(); - } -// MoveWindow(0,0,cx,cy); -} - -/* -void ETSLayoutFormView::UpdateLayout() -{ - ETSLayoutMgr::UpdateLayout(); - - if(m_RootPane.IsValid()) { - // Force MainFrame to re-layout - CFrameWnd* pFrame = static_cast(GetParent()); - if(pFrame) { - - CRect rcWnd; - pFrame->GetWindowRect(rcWnd); - pFrame->MoveWindow(rcWnd); - pFrame->RecalcLayout(); - - } - return; - } -} -*/ - -void ETSLayoutFormView::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) -{ - // To use this you'll have to modify your CMainFrame: - // - // 1) Add a handler for WM_GETMINMAXINFO() - // 2) Let this handler be: - // void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) - // { - // CFrameWnd::OnGetMinMaxInfo(lpMMI); - // - // if( GetActiveView() && GetActiveView()->IsKindOf( RUNTIME_CLASS(ETSLayoutFormView) ) ) { - // GetActiveView()->SendMessage( WM_GETMINMAXINFO, 0, (LPARAM) lpMMI ); - // } - // } - // 3) Add "#include "dialogmgr.h" to MainFrm.cpp - - if(m_RootPane.IsValid()) { - CRect rcClient = GetRect(); - - CRect rcWnd; - GetParent()->GetWindowRect(rcWnd); - - // How much do Window and Client differ - rcWnd-=rcClient; - - // Take into account that there is a border around the rootPane - lpMMI->ptMinTrackSize = CPoint(m_RootPane->getMinConstrainHorz() + rcWnd.Width() + 2*m_sizeRootBorders.cx, - m_RootPane->getMinConstrainVert() + rcWnd.Height() + 2*m_sizeRootBorders.cy); - - int maxWidth = m_RootPane->getMaxConstrainHorz(); - int maxHeight = m_RootPane->getMaxConstrainVert(); - - if( maxWidth != -1 ) { - lpMMI->ptMaxTrackSize.x = maxWidth + rcWnd.Width()+ 2*m_sizeRootBorders.cx; - lpMMI->ptMaxSize.x = maxWidth + rcWnd.Width()+ 2*m_sizeRootBorders.cx; - } - - if( maxHeight != -1 ) { - lpMMI->ptMaxTrackSize.y = maxHeight + rcWnd.Height() + 2*m_sizeRootBorders.cy; - lpMMI->ptMaxSize.y = maxHeight + rcWnd.Height() + 2*m_sizeRootBorders.cy; - } - } -} - -ETSLayoutFormView::~ETSLayoutFormView() -{ - // Cleanup -} - - -///////////////////////////////////////////////////////////////////////////// -// ETSLayoutPropertyPage - -#ifdef CS_HELP - IMPLEMENT_DYNCREATE(ETSLayoutPropertyPage, ETSCSHelpPropPage) -#else - IMPLEMENT_DYNCREATE(ETSLayoutPropertyPage, CPropertyPage) -#endif - -#pragma warning(disable: 4355) -ETSLayoutPropertyPage::ETSLayoutPropertyPage( ) : ETSLayoutMgr( this ) -{ - m_bLockMove = false; - m_bResetBuddyOnNextTimeVisible = true; -} - -ETSLayoutPropertyPage::ETSLayoutPropertyPage( UINT nIDTemplate, UINT nIDCaption /*= 0*/ ) - : CBasePropertyPage(nIDTemplate, nIDCaption), ETSLayoutMgr( this ) -{ - m_bLockMove = false; - m_bResetBuddyOnNextTimeVisible = true; -} - -ETSLayoutPropertyPage::ETSLayoutPropertyPage( LPCTSTR lpszTemplateName, UINT nIDCaption /*= 0*/ ) - : CBasePropertyPage(lpszTemplateName, nIDCaption), ETSLayoutMgr( this ) -{ - m_bLockMove = false; - m_bResetBuddyOnNextTimeVisible = true; -} -#pragma warning(default: 4355) - -ETSLayoutPropertyPage::~ETSLayoutPropertyPage() -{ -} - - -BEGIN_MESSAGE_MAP(ETSLayoutPropertyPage, CBasePropertyPage) - //{{AFX_MSG_MAP(ETSLayoutPropertyPage) - ON_WM_SIZE() - ON_WM_GETMINMAXINFO() - ON_WM_ERASEBKGND() - ON_WM_WINDOWPOSCHANGING() - ON_WM_DESTROY() - ON_WM_WINDOWPOSCHANGED() - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - - -///////////////////////////////////////////////////////////////////////////// -// Behandlungsroutinen fr Nachrichten ETSLayoutPropertyPage - - - -void ETSLayoutPropertyPage::OnWindowPosChanged(WINDOWPOS FAR* lpwndpos) -{ - CBasePropertyPage::OnWindowPosChanged(lpwndpos); - - // This code is needed in order to reset the buddy after this page has - // been activated. At least on Win2k this is not done thru normal resizing, - // as the page is not visible when first layouted. And without the page - // being visible it's not possible to tell if the attached buddy is visible - // or not (at least I don't know any way to do so) - - if( ::IsWindowVisible( GetWnd()->GetSafeHwnd() ) ) - { - if( m_bResetBuddyOnNextTimeVisible ) - { - // Take special care of SpinButtons (Up-Down Controls) with Buddy set, enumerate - // all childs: - CWnd* pWndChild = GetWnd()->GetWindow(GW_CHILD); - TCHAR szClassName[ MAX_PATH ]; - while(pWndChild) - { - ::GetClassName( pWndChild->GetSafeHwnd(), szClassName, MAX_PATH ); - DWORD dwStyle = pWndChild->GetStyle(); - - // is it a SpinButton? - if( _tcscmp(szClassName, UPDOWN_CLASS)==0 && ::IsWindowVisible(pWndChild->GetSafeHwnd()) ) { - HWND hwndBuddy = (HWND)::SendMessage( pWndChild->GetSafeHwnd(), UDM_GETBUDDY, 0, 0); - if( hwndBuddy != 0 && (dwStyle&(UDS_ALIGNRIGHT|UDS_ALIGNLEFT)) != 0 ) - { - // reset Buddy - ::SendMessage( pWndChild->GetSafeHwnd(), UDM_SETBUDDY, (WPARAM)hwndBuddy, 0); - } - } - - - pWndChild = pWndChild->GetWindow(GW_HWNDNEXT); - } - - m_bResetBuddyOnNextTimeVisible = false; - } - } - else - { - // has been hidden again - m_bResetBuddyOnNextTimeVisible = true; - } -} - -void ETSLayoutPropertyPage::OnWindowPosChanging( WINDOWPOS* lpwndpos ) -{ - // In WizardMode the System calls SetWindowPos with the - // original size at every activation. This could cause - // some flicker in certain circumstances. Therefore we lock - // moving the page and unlock it only if _we_ move the page - if( m_bLockMove) - { - lpwndpos->flags |= SWP_NOMOVE | SWP_NOSIZE; - } - CBasePropertyPage::OnWindowPosChanging( lpwndpos ); -} - -BOOL ETSLayoutPropertyPage::OnEraseBkgnd(CDC* pDC) -{ - EraseBkgnd(pDC); - return true; -} - -void ETSLayoutPropertyPage::OnDestroy() -{ - // manually delete layout definition if object is reused - m_RootPane = 0; - - CBasePropertyPage::OnDestroy(); -} - -void ETSLayoutPropertyPage::OnSize(UINT nType, int cx, int cy) -{ - CBasePropertyPage::OnSize(nType, cx, cy); - - if( abs(cx) + abs(cy) > 0) - { - // Re-Layout all controls - UpdateLayout(); - } -} - -void ETSLayoutPropertyPage::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) -{ - if(m_RootPane.IsValid()) { - CRect rcClient = GetRect(); - - CRect rcWnd; - GetWindowRect(rcWnd); - - // How much do Window and Client differ - int nDiffHorz = rcWnd.Width() - rcClient.Width(); - int nDiffVert = rcWnd.Height() - rcClient.Height(); - - // Take into account that there is a border around the rootPane - lpMMI->ptMinTrackSize = CPoint(m_RootPane->getMinConstrainHorz() + nDiffHorz + 2*m_sizeRootBorders.cx, - m_RootPane->getMinConstrainVert() + nDiffVert + 2*m_sizeRootBorders.cy); - - int maxWidth = m_RootPane->getMaxConstrainHorz(); - int maxHeight = m_RootPane->getMaxConstrainVert(); - - if( maxWidth != -1 ) { - lpMMI->ptMaxTrackSize.x = maxWidth + nDiffHorz + 2*m_sizeRootBorders.cx; - lpMMI->ptMaxSize.x = maxWidth + nDiffHorz + 2*m_sizeRootBorders.cx; - } - - if( maxHeight != -1 ) { - lpMMI->ptMaxTrackSize.y = maxHeight + nDiffVert + 2*m_sizeRootBorders.cy; - lpMMI->ptMaxSize.y = maxHeight + nDiffVert + 2*m_sizeRootBorders.cy; - } - } -} - - -CRect ETSLayoutPropertyPage::GetRect() -{ - CRect r; - GetClientRect(r); - return r; -} - - -BOOL ETSLayoutPropertyPage::OnInitDialog() -{ - CBasePropertyPage::OnInitDialog(); - UpdateLayout(); - - ETSLayoutPropertySheet* pSheet = (ETSLayoutPropertySheet*) GetParent(); - - ASSERT_KINDOF( ETSLayoutPropertySheet, pSheet); - if(pSheet) - { - if(pSheet->IsWizard()) - { - m_bLockMove = true; - } - } - - return TRUE; -} - -BOOL ETSLayoutPropertyPage::OnSetActive() -{ - ETSLayoutPropertySheet* pSheet = (ETSLayoutPropertySheet*) GetParent(); - - ASSERT_KINDOF( ETSLayoutPropertySheet, pSheet); - if(pSheet) - { - if(pSheet->IsWizard()) - { - // In WizardMode the System calls SetWindowPos with the - // original size on Page Activation. This will position the - // page at the correct position - m_bLockMove = false; - MoveWindow(pSheet->m_rcPage); - m_bLockMove = true; - } - } - - UpdateLayout(); - - return CBasePropertyPage::OnSetActive(); -} - -///////////////////////////////////////////////////////////////////////////// -// ETSLayoutPropertySheet - -IMPLEMENT_DYNAMIC(ETSLayoutPropertySheet, CPropertySheet) - -#pragma warning(disable: 4355) -ETSLayoutPropertySheet::ETSLayoutPropertySheet(UINT nIDCaption, CWnd* pParentWnd, UINT iSelectPage, - LPCTSTR strName /*=NULL*/, bool bGripper/*=true*/) - : CPropertySheet(nIDCaption, pParentWnd, iSelectPage), ETSLayoutMgr( this ) -{ - Init(strName, bGripper); -} - -ETSLayoutPropertySheet::ETSLayoutPropertySheet(LPCTSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage, - LPCTSTR strName /*=NULL*/, bool bGripper/*=true*/) - : CPropertySheet(pszCaption, pParentWnd, iSelectPage), ETSLayoutMgr( this ) -{ - Init(strName, bGripper); -} -#pragma warning(default: 4355) - -void ETSLayoutPropertySheet::Init(LPCTSTR strName, bool bGripper) -{ - m_bGripper = bGripper; - if(strName) - m_strRegStore = strName; - - m_bAutoDestroy = false; - m_bAutoDestroyPages = false; - m_bModelessButtons = false; -} - -ETSLayoutPropertySheet::~ETSLayoutPropertySheet() -{ -} - - -BEGIN_MESSAGE_MAP(ETSLayoutPropertySheet, CPropertySheet) - //{{AFX_MSG_MAP(ETSLayoutPropertySheet) - ON_WM_CREATE() - ON_WM_SIZE() - ON_WM_GETMINMAXINFO() - ON_WM_DESTROY() - ON_WM_ERASEBKGND() - //}}AFX_MSG_MAP -END_MESSAGE_MAP() - -///////////////////////////////////////////////////////////////////////////// -// Behandlungsroutinen fr Nachrichten ETSLayoutPropertySheet - -BOOL ETSLayoutPropertySheet::OnEraseBkgnd(CDC* pDC) -{ - EraseBkgnd(pDC); - return true; -} - - -int ETSLayoutPropertySheet::OnCreate(LPCREATESTRUCT lpCreateStruct) -{ - if (CPropertySheet::OnCreate(lpCreateStruct) == -1) - return -1; - - ModifyStyle(0,WS_THICKFRAME| WS_SYSMENU); - return 0; -} - - -void ETSLayoutPropertySheet::Resize(int cx, int cy) -{ - if( abs(cx) + abs(cy) > 0 && m_RootPane.IsValid() ) - { - UpdateLayout(); - - // Fix for PSH_WIZARDHASFINISH [Thmmi] - if (IsWizard() && !(m_psh.dwFlags & PSH_WIZARDHASFINISH) ) - { - // manual reposition of the FINISH button - // can not be done with normaly layouting because it - // shares position with the NEXT button - CWnd *pWndFinish; - pWndFinish=GetDlgItem(ID_WIZFINISH); - - if(pWndFinish) - { - CRect rcWnd; - GetDlgItem(ID_WIZNEXT)->GetWindowRect(&rcWnd); - ScreenToClient(&rcWnd); - pWndFinish->MoveWindow(rcWnd); - pWndFinish->RedrawWindow(0,0, RDW_INVALIDATE | RDW_UPDATENOW ); - } - } - - // reposition Gripper - if(m_bGripper) - RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0); - - CPropertyPage* pPage = (CPropertyPage*)GetActivePage(); - - if(pPage) - { - CRect rcWnd; - GetTabControl()->GetWindowRect(&rcWnd); - ScreenToClient(&rcWnd); - - if(!IsWizard()) { - // get inside of tab - GetTabControl()->AdjustRect(FALSE, &rcWnd); - } - else - { - rcWnd.bottom += 5; - } - - // we need this size in WizardMode in order to - // reposition newly activated page correctly - m_rcPage = rcWnd; - - if( IsWizard() && pPage->IsKindOf(RUNTIME_CLASS(ETSLayoutPropertyPage)) ) - { - ETSLayoutPropertyPage* pEtsPage = reinterpret_cast(pPage); - - pEtsPage->m_bLockMove = false; - pEtsPage->MoveWindow(m_rcPage); - pEtsPage->m_bLockMove = true; - } - else - { - pPage->MoveWindow(m_rcPage); - } - - } - - if(IsWindowVisible()) - { - RedrawWindow(0,0, RDW_INVALIDATE|RDW_UPDATENOW ); - - if(!IsWizard()) - GetTabControl()->RedrawWindow(0,0, RDW_INVALIDATE|RDW_UPDATENOW ); - } - } -} - -void ETSLayoutPropertySheet::OnSize(UINT nType, int cx, int cy) -{ - CPropertySheet::OnSize(nType, cx, cy); - Resize(cx,cy); -} - -// IDs of all PropertySheet controls -long _PropertySheetIDs[] = -{ - ID_WIZBACK, - ID_WIZNEXT, - ID_WIZFINISH, - IDOK, - IDCANCEL, - ID_APPLY_NOW, - IDHELP -}; - -void ETSLayoutPropertySheet::AddMainArea(CPane paneRoot, CPaneBase itemTab) -{ - // the default is: Whole main Area is covered by the TabCtrl - paneRoot << itemTab; -} - -void ETSLayoutPropertySheet::AddButtons(CPane paneBottom) -{ - // first item greedy to keep others right - paneBottom->addItem (paneNull, GREEDY); - - - // add all Controls to the layouting - bool bFirst = true; - for(int i = 0; i < (sizeof(_PropertySheetIDs) / sizeof(long)) ; i++) - { - // Prevent movement of finish button, if it is not shown explicitly [Thmmi] - if( IsWizard() - && _PropertySheetIDs[i] == ID_WIZFINISH - && !(m_psh.dwFlags & PSH_WIZARDHASFINISH) ) - { - continue; - } - - CWnd* pWnd = GetDlgItem(_PropertySheetIDs[i]); - - if(pWnd) - { - - if(!(m_psh.dwFlags & PSH_HASHELP) && _PropertySheetIDs[i] == IDHELP) - { - // don't insert - continue; - } - - if((m_psh.dwFlags & PSH_NOAPPLYNOW) && _PropertySheetIDs[i] == ID_APPLY_NOW) - { - // don't insert - continue; - } - - // space before first one and between BACK & NEXT - if( IsWizard() ) - { - if( !bFirst && !(_PropertySheetIDs[i]==ID_WIZNEXT) ) - { - paneBottom->addItem(paneNull, NORESIZE,12,0,0,0); - } - } - - pWnd->ShowWindow(true); - paneBottom->addItem(_PropertySheetIDs[i], NORESIZE); - bFirst = false; - } - } - -} - -BOOL ETSLayoutPropertySheet::OnInitDialog() -{ - BOOL bRet = CPropertySheet::OnInitDialog(); - - ASSERT(!m_RootPane); - - // Save initial rect - GetWindowRect(&m_rcStart); - - CPropertyPage* pPage = CPropertySheet::GetActivePage(); - ASSERT(pPage); - - CRect rcPage; - pPage->GetClientRect(&rcPage); - - CreateRoot(VERTICAL); - ASSERT(m_RootPane.IsValid()); - - // Add Tabcontrol to root pane - m_ItemTab = item( GetTabControl(), GREEDY, 0, 0, 0, 0); - AddMainArea(m_RootPane, m_ItemTab); - - // Tabcontrol is invisible in WizardMode - if(IsWizard()) - { - GetTabControl()->ShowWindow(false); - } - - // add horizontal line in WizardMode - if(IsWizard() && GetDlgItem(ID_WIZFINISH+1)) - { - m_RootPane << item(ID_WIZFINISH+1, ABSOLUTE_VERT, 0, 0, 0, 0); - } - - if( IsWizard() || !m_bModeless || m_bModelessButtons ) - { - // No spaces in WizardMode in order to keep BACK & NEXT together - CPane bottomPane = pane(HORIZONTAL, ABSOLUTE_VERT, IsWizard() ? 0 : 5); - - AddButtons(bottomPane); - // add bottom (button) pane if any controls were added - if(bottomPane->m_paneItems.GetSize() > 0) { - m_RootPane << bottomPane; - } - } - - - - // some Space between Buttons und Gripper - if(m_bGripper) - { - m_RootPane->addItem(paneNull, ABSOLUTE_VERT,0,2); - - if(m_StatusBar.Create(m_pWnd)) - { - m_StatusBar.SetIndicators(auIDStatusBar, - sizeof(auIDStatusBar) / sizeof(UINT)); - m_StatusBar.SetWindowText(_T("")); - RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0); - } - else - { - AfxMessageBox(_T("Error - Statusbar")); - } - } - - if(!m_strRegStore.IsEmpty()) - { - Load(m_strRegStore); - } - - Resize(1,1); // Fix. for 95/98/NT difference - - CRect rcWnd; - GetWindowRect( & rcWnd ); - MoveWindow( rcWnd ); - - return bRet; -} - - -void ETSLayoutPropertySheet::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) -{ - if(m_RootPane.IsValid() && GetTabControl() != 0 ) - { - CRect rcWnd; - GetWindowRect(rcWnd); - - CRect rcClient = GetRect(); - rcWnd-=rcClient; - - // ask for MinMax of all pages - CSize sizePageMax(0,0); - CSize sizePageMin(0,0); - for( int nPage=0; nPageGetSafeHwnd()) ) - { - pPage->SendMessage(WM_GETMINMAXINFO, 0, (LPARAM) &mmi); - - if(mmi.ptMaxTrackSize.x != 0) - { - sizePageMax.cx = min(sizePageMax.cx, mmi.ptMaxTrackSize.x); - } - if(mmi.ptMaxTrackSize.y != 0) - { - sizePageMax.cy = min(sizePageMax.cy, mmi.ptMaxTrackSize.y); - } - if(mmi.ptMinTrackSize.x != 0) - { - sizePageMin.cx = max(sizePageMin.cx, mmi.ptMinTrackSize.x); - } - if(mmi.ptMinTrackSize.y != 0) - { - sizePageMin.cy = max(sizePageMin.cy, mmi.ptMinTrackSize.y); - } - } - } - } - static_cast( m_ItemTab.GetPaneBase() )->m_sizeXMin = sizePageMin.cx; - static_cast( m_ItemTab.GetPaneBase() )->m_sizeYMin = sizePageMin.cy; - - // calculate the needed size of the tabctrl in non-wizard-mode - CRect rcItem(0,0,0,0); - if(!IsWizard()) - { - GetTabControl()->AdjustRect( TRUE, rcItem ); - } - - lpMMI->ptMinTrackSize.x = m_RootPane->getMinConstrainHorz() + rcWnd.Width() + 2*m_sizeRootBorders.cx - + rcItem.Width(); - - lpMMI->ptMinTrackSize.y = m_RootPane->getMinConstrainVert() + rcWnd.Height() + 2*m_sizeRootBorders.cy - + rcItem.Height(); - - // never smaller than inital size! - lpMMI->ptMinTrackSize.x = max(lpMMI->ptMinTrackSize.x, m_rcStart.Width() ); - lpMMI->ptMinTrackSize.y = max(lpMMI->ptMinTrackSize.y, m_rcStart.Height() ); - - // Rest like ETSLayoutMgr - - int maxWidth = m_RootPane->getMaxConstrainHorz(); - int maxHeight = m_RootPane->getMaxConstrainVert(); - - if( maxWidth != -1 ) - { - lpMMI->ptMaxSize.x = sizePageMax.cx + rcWnd.Width()+ 2*m_sizeRootBorders.cx + rcItem.Width() ; - } - - if( maxHeight != -1 ) - { - lpMMI->ptMaxSize.y = sizePageMax.cy + rcWnd.Height() + 2*m_sizeRootBorders.cy + rcItem.Width() ; - } - - lpMMI->ptMaxTrackSize = lpMMI->ptMaxSize; - - } -} - - -void ETSLayoutPropertySheet::OnDestroy() -{ - // Store size/position - if(!m_strRegStore.IsEmpty()) - { - Save(m_strRegStore); - } - m_RootPane = 0; - - CPropertySheet::OnDestroy(); -} - -void ETSLayoutPropertySheet::PostNcDestroy() -{ - if(m_bAutoDestroyPages) - { - // walk all pages and destry them - for( int nPage=0; nPageRelease(); -} - -void ETSLayoutMgr::CPaneBase::operator=( PaneBase* pPane ) -{ - if(m_pPaneHolder) - { - m_pPaneHolder->Release(); - m_pPaneHolder = 0; - } - - if( pPane != 0 ) - m_pPaneHolder = new PaneHolder( pPane ); -} - -void ETSLayoutMgr::CPaneBase::operator=( const CPaneBase& other ) -{ - ASSERT( other.m_pPaneHolder ); - - if(m_pPaneHolder) - { - m_pPaneHolder->Release(); - m_pPaneHolder = 0; - } - - other.m_pPaneHolder->AddRef(); - m_pPaneHolder = other.m_pPaneHolder; -} - -ETSLayoutMgr::PaneBase* ETSLayoutMgr::CPaneBase::operator->() const -{ - ASSERT(m_pPaneHolder); - - if(!m_pPaneHolder) - return 0; - - return (m_pPaneHolder->m_pPane); -} - - - -ETSLayoutMgr::CPane::CPane( ) -{ -} - -ETSLayoutMgr::CPane::CPane( Pane* pPane ) : ETSLayoutMgr::CPaneBase( static_cast(pPane) ) -{ -} - -ETSLayoutMgr::CPane::CPane( const CPane& other ) -{ - operator=(other); -} - -ETSLayoutMgr::CPane::~CPane() -{ -} - -void ETSLayoutMgr::CPane::operator=( Pane* pPane ) -{ - CPaneBase::operator=(pPane); -} - -void ETSLayoutMgr::CPane::operator=( const ETSLayoutMgr::CPane& other ) -{ - ASSERT( other.m_pPaneHolder ); - - if(m_pPaneHolder) - { - m_pPaneHolder->Release(); - m_pPaneHolder = 0; - } - - other.m_pPaneHolder->AddRef(); - m_pPaneHolder = other.m_pPaneHolder; -} - -ETSLayoutMgr::Pane* ETSLayoutMgr::CPane::operator->() const -{ - ASSERT(m_pPaneHolder); - - if(!m_pPaneHolder) - return 0; - - return reinterpret_cast(m_pPaneHolder->m_pPane); -} - -ETSLayoutMgr::CPaneBase ETSLayoutMgr::CPane::ConvertBase() const -{ - ASSERT(m_pPaneHolder); - return CPaneBase( m_pPaneHolder->m_pPane ); -} - -ETSLayoutMgr::CPane& ETSLayoutMgr::CPane::operator<< ( const ETSLayoutMgr::CPane pPane ) -{ - GetPane()->addPane( pPane, (ETSLayoutMgr::layResizeMode)pPane->m_modeResize, pPane->m_sizeSecondary); - return (*this); -} - -ETSLayoutMgr::CPane& ETSLayoutMgr::CPane::operator<< ( const ETSLayoutMgr::CPaneBase pItem ) -{ - GetPane()->addPane( pItem ); - return (*this); -} diff --git a/install/xbt/linux/misc/windows/ETSLayout.h b/install/xbt/linux/misc/windows/ETSLayout.h deleted file mode 100644 index 43d912fcc..000000000 --- a/install/xbt/linux/misc/windows/ETSLayout.h +++ /dev/null @@ -1,964 +0,0 @@ -//////////////////////////////////////////// -// ___ ____ _________________ // -// / _/_ _// _______________/ // -// / _/ / / / / ___ ___ ____ // -// /__/ /_/ / / / // _/_ _/ // -// _________/ / / / // _/ / / // -// (c) 1998-2000_/ /___//_/ /_/ // -// // -//////////////////////////////////////////// -// all rights reserved // -//////////////////////////////////////////// - -///////////////////////////////////////////////////////////////////////////// -// ETSLayoutDialog -// -// A class for smart layouting of Dialogs and such -// -// USAGE: See LayoutMgr.html -// -// AUTHOR: Erwin Tratar -// -// DISCLAIMER: -// -// This Sourcecode and all accompaning material is 1998-1999 Erwin Tratar. -// All rights reserved. -// -// The source code may be used in compiled form in any way you desire -// (including usage in commercial applications), providing that your -// application adds essential code (i.e. it is not only a wrapper) to the -// functionality found here -// -// Redistribution of the sourcecode itself, publication in any media or -// inclusion in a library requires the authors expressed written consent. -// You may not sale this code for profit. -// -// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. USE IT -// AT YOUR OWN RISK! THE AUTHOR ACCEPTS NO LIABILITY FOR ANY DAMAGE/LOSS OF -// BUSINESS THAT THIS PRODUCT MAY CAUSE. - - -#if !defined(ETS_LAYOUTMGR_INCLUDED_) -#define ETS_LAYOUTMGR_INCLUDED_ - -#if _MSC_VER >= 1000 -#pragma once -#endif // _MSC_VER >= 1000 -// DialogMgr.h : header file -// - -namespace ETSLayout -{ - -#ifdef CS_HELP - typedef ETSCSHelpDialog CBaseDialog; - typedef ETSCSHelpFormView CBaseFormView; - typedef ETSCSHelpDlgBar CBaseDialogBar; - typedef ETSCSHelpPropPage CBasePropertyPage; -#else - typedef CDialog CBaseDialog; - typedef CFormView CBaseFormView; - typedef CDialogBar CBaseDialogBar; - typedef CPropertyPage CBasePropertyPage; -#endif -} - -// Support for CBCGDialogBar instead of CDialogBar available: -// you just have to change the typedef to CBaseDialogBar - -#ifndef ETSGUI_EXT_CLASS -#define ETSGUI_EXT_CLASS -#endif - -#include - -// Support for CBCGDialogBar instead of CDialogBar - -/** - * Controls whether the Icon is automatically set to IDR_MAINFRAME - */ -#define _AUTO_SET_ICON - -/** - * Forward class declarations - */ -class ETSLayoutDialog; -class ETSLayoutDialogBar; -class ETSLayoutFormView; -class ETSLayoutMgr; -class ETSLayoutPropertyPage; -class ETSLayoutPropertySheet; - - -/** - * These are NOOPs now - */ -#define DECLARE_LAYOUT() -#define IMPLEMENT_LAYOUT() - -/** - * This is the default border size between the panes. You - * may override it in Pane constructor, but it is the - * fixed border around the root pane - */ -const int nDefaultBorder = 5; - -/** - * The minimum size for not ABSOLUTE_XXX items - */ -const int nMinConstrain = 5; - -class ETSGUI_EXT_CLASS ETSLayoutMgr -{ -public: - - enum layResizeMode { - GREEDY = 0, // Will eat up as much as it can - ABSOLUTE_HORZ = 1 << 0, // Horizontal size is absolute - RELATIVE_HORZ = 1 << 1, // Horizontal size in percent - ABSOLUTE_VERT = 1 << 2, // Vertical size is absolute - RELATIVE_VERT = 1 << 3, // Vertical size in percent - - NORESIZE = ABSOLUTE_HORZ | ABSOLUTE_VERT, - - SIZE_MASK = NORESIZE, - - ALIGN_LEFT = 1 << 4, // following only for NORESIZE - ALIGN_RIGHT = 1 << 5, - ALIGN_TOP = 1 << 6, - ALIGN_BOTTOM = 1 << 7, - - ALIGN_HCENTER = ALIGN_LEFT | ALIGN_RIGHT, - ALIGN_VCENTER = ALIGN_TOP | ALIGN_BOTTOM, - - ALIGN_CENTER = ALIGN_HCENTER | ALIGN_VCENTER, - - ALIGN_FILL_HORZ = 1 << 8, - ALIGN_FILL_VERT = 1 << 9, - ALIGN_FILL = ALIGN_FILL_HORZ | ALIGN_FILL_VERT, - -/* TRACKER_LEFT = 1 << 10, // not yet. May allow tracking of borders - TRACKER_RIGHT = 1 << 11, // between items in the future - TRACKER_TOP = 1 << 12, - TRACKER_BOTTOM = 1 << 13, -*/ - }; - - enum layOrientation { - HORIZONTAL, - VERTICAL - }; - - /** - * This is the base class for all kind of panes. - */ - class ETSGUI_EXT_CLASS PaneBase { - friend class ETSLayoutMgr; - friend class CPaneBase; - friend class CPane; - - public: - - /** - * Informs the caller how much of the given space this pane would - * like to receive in horizontal direction - */ - virtual int getConstrainHorz(int sizeParent) = 0; - - - /** - * Informs the caller how much of the given space this pane would - * like to receive in vertical direction - */ - virtual int getConstrainVert(int sizeParent) = 0; - - /** - * Informs the caller how much of the given space this pane - * minimally need. This would be an absolute Value if - * the mode contains ABSOLUTE_HORZ or an explicit minimum - * value, else nMinConstrain - */ - virtual int getMinConstrainHorz() = 0; - /** - * Informs the caller if there is an restriction for maximum - * space this pane needs. Return -1 for unrestricted (GREEDY - * or RELATIVE) - */ - virtual int getMaxConstrainHorz() = 0; - - /** - * Informs the caller how much of the given space this pane - * minimally need. This would be an absolute Value if - * the mode contains ABSOLUTE_VERT or an explicit minimum - * value, else nMinConstrain - */ - virtual int getMinConstrainVert() = 0; - - /** - * Informs the caller if there is an restriction for maximum - * space this pane needs. Return -1 for unrestricted (GREEDY - * or RELATIVE) - */ - virtual int getMaxConstrainVert() = 0; - - /** - * This will do the actual resize operation after the - * caller computed a new area for this pane - */ - virtual bool resizeTo(CRect& rcNewArea) = 0; - - /** - * Constructor needed pointer to LayoutManager - */ - PaneBase( ETSLayoutMgr* pMgr ) { m_pMgr = pMgr; }; - - /** - * Virtual destructor needed in Container operations - */ - virtual ~PaneBase() {}; - - /** - * Returs the Resize Mode of this pane - */ - DWORD modeResize() { return m_modeResize; }; - - protected: - /** - * How this Item will be resized, a combination of the flags above - */ - DWORD m_modeResize; - - /** - * A pointer to the holding LayoutManager derivate - */ - ETSLayoutMgr* m_pMgr; - }; - - /** - * CPaneBase represents an autopointer to a PaneBase. Use this and you won't have to worry - * about cleaning up any Panes. Also this autopointer lets you return Pane objects - * from function without using pointers (at least you won't see them :) ) - */ - struct ETSGUI_EXT_CLASS PaneHolder - { - PaneHolder(PaneBase* pPane ); - ~PaneHolder(); - - void AddRef(); - void Release(); - - PaneBase* m_pPane; - long m_nRefCount; - }; - - class ETSGUI_EXT_CLASS CPaneBase - { - protected: - PaneHolder* m_pPaneHolder; - - public: - // Standardconstructor - CPaneBase( ); - CPaneBase( PaneBase* pPane ); - CPaneBase( const CPaneBase& other ); - - ~CPaneBase(); - - void operator=( PaneBase* pPane ); - void operator=( const CPaneBase& other ); - PaneBase* operator->() const; - PaneBase* GetPaneBase() { return operator->(); } - - bool IsValid() { return (m_pPaneHolder != 0); } - bool operator !() { return (m_pPaneHolder == 0); } - - }; - - class Pane; - class ETSGUI_EXT_CLASS CPane : public CPaneBase - { - public: - // Standardconstructor - CPane( ); - CPane( Pane* pPane ); - CPane( const CPane& other ); - - ~CPane(); - - void operator=( Pane* pPane ); - void operator=( const CPane& other ); - Pane* operator->() const; - Pane* GetPane() { return operator->(); } - - CPaneBase ConvertBase() const; - - CPane& operator<< ( const CPane pPane ); - CPane& operator<< ( const CPaneBase pItem ); - }; - - - - /** - * PaneItem represents a single control - */ - class ETSGUI_EXT_CLASS PaneItem : public PaneBase { - friend class ETSLayoutMgr; - friend class Pane; - protected: - /** - * Creates a new PaneItem from an Control. If sizeX or sizeY are 0 - * and modeResize is ABSOLUTE will copy the current dimensions of - * the control to m_sizeX/Y. So the appearance does not change - * from the Dialog Editor - */ - PaneItem( CWnd* pWnd, ETSLayoutMgr* pMgr, layResizeMode modeResize = GREEDY, int sizeX=0, int sizeY=0, int sizeXMin=0, int sizeYMin=0); - - /** - * If your control is not mapped you can name it by its ChildID. Pass - * the pMgr to receive the CWnd* of nID. - * The rest as stated above - */ - PaneItem( UINT nID, ETSLayoutMgr* pMgr, layResizeMode modeResize = GREEDY, int sizeX=0, int sizeY=0, int sizeXMin=0, int sizeYMin=0); - - - public: - /** - * see PaneBase - */ - virtual int getConstrainHorz(int sizeParent); - virtual int getConstrainVert(int sizeParent); - virtual int getMinConstrainHorz(); - virtual int getMinConstrainVert(); - virtual int getMaxConstrainHorz(); - virtual int getMaxConstrainVert(); - virtual bool resizeTo(CRect& rcNewArea); - - bool isDummy() { return (m_hwndCtrl == 0); } - - protected: - friend class ETSLayoutPropertySheet; - - /** - * The horizontal size of the control (see m_modeResize) - */ - int m_sizeX; - int m_sizeXMin; - - /** - * The vertical size of the control (see m_modeResize) - */ - int m_sizeY; - int m_sizeYMin; - - /** - * Child Control pointer - */ - HWND m_hwndCtrl; - - /** - * Combo box needs special treatment - */ - bool m_bComboSpecial; - }; - - - /** - * This class encapsulates a Subpane (and indeed the root Pane too) - * it is a container of PaneBase* which it will recursivly resize - */ - class ETSGUI_EXT_CLASS Pane : public PaneBase { - friend class ETSLayoutMgr; - friend class CPaneBase; - friend class CPane; - friend class ETSLayoutPropertySheet; - - protected: - /** - * Tell the pane in which direction it is positioned. A HORIZONTAL pane - * arranges it's subpanes from left to right, a VERTICAL from top to bottom - */ - Pane( ETSLayoutMgr* pMgr, layOrientation orientation, int sizeBorder = nDefaultBorder, int sizeExtraBorder = 0 ); - - public: - /** - * If your control is not mapped you can name it by its ChildID. Pass - * the pMgr to receive the CWnd* of nID. - * The rest as stated above - */ - bool addItem( UINT nID, layResizeMode modeResize = GREEDY, int sizeX=0, int sizeY=0, int sizeXMin=-1, int sizeYMin=-1); - - /** - * Creates a new PaneItem from an Control. If sizeX or sizeY are 0 - * and modeResize is ABSOLUTE will copy the current dimensions of - * the control to m_sizeX/Y. So the appearance does not change - * from the Dialog Editor - */ - bool addItem( CWnd* pWnd, layResizeMode modeResize = GREEDY, int sizeX=0, int sizeY=0, int sizeXMin=-1, int sizeYMin=-1); - - - /** - * Add a whitespace Item (paneNull) of variable size with - * a minimum size of 0 - */ - bool addItemGrowing(); - - /** - * Add a whitespace Item (paneNull) with fixed size - */ - bool addItemFixed(int size); - - /** - * Add a whitespace Item (paneNull) of fixed size based on the - * current layout (as in the dialog template). Based on the layout - * of the pane vertical or horizontal spacing is considered - * - * First argument is the left (top) item for a HORIZONTAL (VERTICAL) pane - */ - bool addItemSpaceBetween( CWnd* pWndFirst, CWnd* pWndSecond ); - bool addItemSpaceBetween( UINT nIDFirst, UINT nIDSecond ); - - - /** - * Add a whitespace Item (paneNull) of fixed size based on the - * size of another item - */ - bool addItemSpaceLike( CWnd* pWnd ); - bool addItemSpaceLike( UINT nID ); - - - /** - * Add an item to the pane, appending at the end. This may be either obtained - * by a call to ETSLayoutMgr::item() or one of the ETSLayoutMgr::paneXXX() calls - */ - bool addPane( CPaneBase pItem ); - bool addPane( CPane pSubpane, layResizeMode modeResize, int sizeSecondary /* = 0 */); - - virtual int getConstrainHorz(int sizeParent); - virtual int getConstrainVert(int sizeParent); - virtual int getMinConstrainHorz(); - virtual int getMinConstrainVert(); - virtual int getMaxConstrainHorz(); - virtual int getMaxConstrainVert(); - virtual bool resizeTo(CRect& rcNewArea); - - /** - * The destructor takes care of destroying all Subpanes and items - */ - virtual ~Pane(); - - /** - * Access to the orientation of this pane - */ - layOrientation getOrientation() { return m_Orientation; }; - - - protected: - - int resizeToAbsolute(int& availSpace, CArray& sizePrimary, - CArray& sizeMin, CArray& sizeMax); - - bool resizeToRelative(int& availSpace, CArray& sizePrimary, - CArray& sizeMin, CArray& sizeMax); - - bool resizeToGreedy( int& availSpace, int nGreedy, CArray& sizePrimary, - CArray& sizeMin, CArray& sizeMax); - - /** - * The orientation of the pane. Keep in mind that all subpanes - * must have the complementary orientation, i.e. a VERTICAL - * pane must have all HORIZONTAL SubPanes (or normal Items - * of course) - */ - layOrientation m_Orientation; - - /** - * This array holds the pointers to the Items/SubPanes - */ - CArray m_paneItems; - - /** - * The secondary constrain - */ - int m_sizeSecondary; - - /** - * Size of gap between childs - */ - int m_sizeBorder; - int m_sizeExtraBorder; - }; - - - /** - * This class encapsulates a Subpane which is a Tab - * it will use calls to AdjustRect to position it's - * childs - */ - class ETSGUI_EXT_CLASS PaneTab : public Pane - { - friend class ETSLayoutMgr; - - protected: - /** - * Tell the pane in which direction it is positioned. A HORIZONTAL pane - * arranges it's subpanes from left to right, a VERTICAL from top to bottom - */ - PaneTab( CTabCtrl* pTab, ETSLayoutMgr* pMgr, layOrientation orientation, int sizeBorder = nDefaultBorder, int sizeExtraBorder = 0 ); - - public: - virtual int getConstrainHorz(int sizeParent); - virtual int getConstrainVert(int sizeParent); - virtual int getMinConstrainHorz(); - virtual int getMinConstrainVert(); - virtual int getMaxConstrainHorz(); - virtual int getMaxConstrainVert(); - virtual bool resizeTo(CRect& rcNewArea); - - private: - CTabCtrl* m_pTab; - }; - - /** - * This class encapsulates a Subpane which is a Static - * it will use calls to AdjustRect to position it's - * childs - */ - class ETSGUI_EXT_CLASS PaneCtrl : public Pane - { - friend class ETSLayoutMgr; - protected: - /** - * Tell the pane in which direction it is positioned. A HORIZONTAL pane - * arranges it's subpanes from left to right, a VERTICAL from top to bottom - */ - PaneCtrl( CWnd* pCtrl, ETSLayoutMgr* pMgr, layOrientation orientation, int sizeBorder = nDefaultBorder, int sizeExtraBorder = 0, int sizeTopExtra = 0); - PaneCtrl( UINT nID, ETSLayoutMgr* pMgr, layOrientation orientation, int sizeBorder = nDefaultBorder, int sizeExtraBorder = 0, int sizeTopExtra = 0 ); - - public: - - virtual int getConstrainHorz(int sizeParent); - virtual int getConstrainVert(int sizeParent); - virtual int getMinConstrainHorz(); - virtual int getMinConstrainVert(); - virtual int getMaxConstrainHorz(); - virtual int getMaxConstrainVert(); - virtual bool resizeTo(CRect& rcNewArea); - - private: - HWND m_hwndCtrl; - int m_sizeTopExtra; - }; - - - - - ETSLayoutMgr(CWnd* pWnd) { m_pWnd = pWnd; m_sizeRootBorders = CSize(5,5); }; - virtual ~ETSLayoutMgr(); - - virtual CRect GetRect() { CRect r; m_pWnd->GetClientRect(r); return r; }; - CWnd* m_pWnd; - CWnd* GetWnd() { return m_pWnd; }; - void setRootBorders(int cx, int cy) { m_sizeRootBorders = CSize(cx,cy); }; - - /** - * Pass this for a pseudo Pane with no content - */ - static CWnd* paneNull; - - /** - * Loads the current position and size from the registry using a supplied - * key. Will be loaded with AfxGetApp()->WriteProfileXXX(). You may - * specify a subfolder (e.g. Load( _T("MyDialog\\Layout") ); ). Will - * load the following keys: - * - * - lpstrRegKey+"SizeX"; - * - lpstrRegKey+"SizeY"; - * - lpstrRegKey+"PosX"; - * - lpstrRegKey+"PosY"; - * - * Is automatically called during OnActivate() if key specified in - * constructor. - */ - bool Load(LPCTSTR lpstrRegKey); - - /** - * Store the current position and size to the registry using a supplied - * key. Will be stored with AfxGetApp()->WriteProfileXXX(). You may - * specify a subfolder (e.g. Save( _T("MyDialog\\Layout") ); ). Will - * create the following keys: - * - * - lpstrRegKey+"SizeX"; - * - lpstrRegKey+"SizeY"; - * - lpstrRegKey+"PosX"; - * - lpstrRegKey+"PosY"; - * - * Is automatically called during DestroyWindow() if key specified in - * constructor. - */ - bool Save(LPCTSTR lpstrRegKey); - - /** - * Updates the layout after you specify the new - * layout - */ - virtual void UpdateLayout(); - virtual void UpdateLayout(CPane p) { - if(m_RootPane.IsValid()) - { - // free old root - m_RootPane = 0; - } - m_RootPane = p; - UpdateLayout(); - } - - /** - * Does the actual Layout, called from OnSize() - * Default implementation does nothing, use - * IMPLEMENT_LAYOUT in your derived class (see above) - */ - virtual void Layout(CRect& rcClient); - - - /** - * Erasing only the these parts of the client area where - * there is no child window. Extra-code for group-boxes - * included! - */ - void EraseBkgnd(CDC* pDC); - - /** - * Helperfunctions for the stream-interface. For usage see sample Application - * and/or documentation. - */ - - /** - * Create a new Pane. You may specify the resize - * mode for both directions. If you add modes for the secondary direction - * (i.e. *_VERT for a HORIZONTAL pane) then sizeSecondary is used as it's - * size. If you do not specify sizeSecondary and the mode is ABSOLUTE_VERT - * it will be computed as the maximum Height of all SubPanes (the same is - * true for VERTICAL panes and subpanes with *_HORZ) - */ - CPane pane( layOrientation orientation, layResizeMode modeResize = GREEDY, int sizeBorder = nDefaultBorder, int sizeExtraBorder = 0, int sizeSecondary = 0); - - /** - * Create one of the special control panes. Parameter are like pane(). For - * additional information see documentation - */ - CPane paneTab( CTabCtrl* pTab, layOrientation orientation, layResizeMode modeResize = GREEDY, int sizeBorder = nDefaultBorder, int sizeExtraBorder = 0, int sizeSecondary = 0); - CPane paneCtrl( UINT nID, layOrientation orientation, layResizeMode modeResize = GREEDY, int sizeBorder = nDefaultBorder, int sizeExtraBorder = 0, int sizeTopExtra = 0, int sizeSecondary = 0); - CPane paneCtrl( CWnd* pCtrl, layOrientation orientation, layResizeMode modeResize = GREEDY, int sizeBorder = nDefaultBorder, int sizeExtraBorder = 0, int sizeTopExtra = 0, int sizeSecondary = 0); - - /** - * Creates a new PaneItem for an Control. If sizeX or sizeY are 0 - * and modeResize is ABSOLUTE will copy the current dimensions of - * the control to m_sizeX/Y. So the appearance does not change - * from the Dialog Editor. size*Min = -1 means: do not make smaller - * than in Dialog Template. - */ - CPaneBase item(UINT nID, layResizeMode modeResize = GREEDY, int sizeX =0, int sizeY =0, int sizeXMin =-1, int sizeYMin =-1); - CPaneBase item(CWnd* pWnd, layResizeMode modeResize = GREEDY, int sizeX =0, int sizeY =0, int sizeXMin =-1, int sizeYMin =-1); - - - /** - * Add a whitespace Item (paneNull) of variable size with - * a minimum size of 0 - */ - CPaneBase itemGrowing(layOrientation orientation); - - /** - * Add a whitespace Item (paneNull) with fixed size - */ - CPaneBase itemFixed(layOrientation orientation, int sizePrimary); - - /** - * Add a whitespace Item (paneNull) of fixed size based on the - * current layout (as in the dialog template). Based on the layout - * of the pane vertical or horizontal spacing is considered - * - * First argument is the left (top) item for a HORIZONTAL (VERTICAL) pane - */ - CPaneBase itemSpaceBetween( layOrientation orientation, CWnd* pWndFirst, CWnd* pWndSecond ); - CPaneBase itemSpaceBetween( layOrientation orientation, UINT nIDFirst, UINT nIDSecond ); - - /** - * Add a whitespace Item (paneNull) of fixed size based on the - * size of another item - */ - CPaneBase itemSpaceLike( layOrientation orientation, CWnd* pWnd ); - CPaneBase itemSpaceLike( layOrientation orientation, UINT nID ); - -protected: - /** - * This holds the root pane. Fill in InitDialog() - */ - CPane m_RootPane; - - /** - * Create a root pane - */ - CPane CreateRoot(layOrientation orientation, int sizeBorder = nDefaultBorder, int sizeExtraBorder = 0 ) - { - if(m_RootPane.IsValid()) - { - // free old root - m_RootPane = 0; - } - m_RootPane = new Pane( this, orientation, sizeBorder, sizeExtraBorder); - return m_RootPane; - } - - /** - * Key in Registry where to store Size - */ - CString m_strRegStore; - - /** - * Borders around root - */ - CSize m_sizeRootBorders; -}; - -inline ETSLayoutMgr::layResizeMode operator|(const ETSLayoutMgr::layResizeMode m1, - const ETSLayoutMgr::layResizeMode m2) - { return (ETSLayoutMgr::layResizeMode)( (DWORD)m1|(DWORD)m2); } - - -/** - * Base class for the Layout function. Derive your own class - * from this or derive it from CDialog and modify _all_ - * references to CDialog to ETSLayoutDialog - */ -class ETSGUI_EXT_CLASS ETSLayoutDialog : public ETSLayout::CBaseDialog, protected ETSLayoutMgr -{ -// Construction -public: - ETSLayoutDialog(UINT nID, CWnd* pParent = NULL, LPCTSTR strName = NULL, bool bGripper = true); // standard constructor - -// Dialog Data - //{{AFX_DATA(ETSLayoutDialog) - //}}AFX_DATA - - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(ETSLayoutDialog) - //}}AFX_VIRTUAL - -// Implementation -protected: - // Generated message map functions - //{{AFX_MSG(ETSLayoutDialog) - afx_msg void OnSize(UINT nType, int cx, int cy); - afx_msg void OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI); - afx_msg BOOL OnEraseBkgnd(CDC* pDC); - virtual BOOL OnInitDialog(); - afx_msg void OnDestroy(); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() - - virtual CRect GetRect(); - - bool m_bGripper; - CStatusBar m_StatusBar; -}; - - -/** - * Base class for the Layout function. Derive your own class - * from this or derive it from CDialog and modify _all_ - * references to CFormView to ETSLayoutFormView - */ -class ETSGUI_EXT_CLASS ETSLayoutFormView : public ETSLayout::CBaseFormView, public ETSLayoutMgr -{ -// Construction - DECLARE_DYNAMIC(ETSLayoutFormView) -public: - ETSLayoutFormView(UINT nID, LPCTSTR strName = NULL); // standard constructor - virtual ~ETSLayoutFormView(); - -// virtual void UpdateLayout(); - - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(ETSLayoutDialog) - //}}AFX_VIRTUAL - -// Implementation -protected: - - // Generated message map functions - //{{AFX_MSG(ETSLayoutDialog) - afx_msg void OnSize(UINT nType, int cx, int cy); - afx_msg BOOL OnEraseBkgnd(CDC* pDC); - afx_msg void OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() -}; - - -/** - * Base class for the Layout function. Derive your own class - * from this or derive it from CBCGDialogBar/CDialogBar and - * modify _all_ references to CBCGDialogBar/CDialogBar to - * ETSLayoutDialogBar - */ -class ETSGUI_EXT_CLASS ETSLayoutDialogBar : public ETSLayout::CBaseDialogBar, protected ETSLayoutMgr -{ -// Construction -public: -#ifdef CS_HELP - ETSLayoutDialogBar(UINT nID); -#else - ETSLayoutDialogBar(); -#endif - - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(ETSLayoutDialogBar) - virtual CSize CalcDynamicLayout(int nLength, DWORD dwMode); - //}}AFX_VIRTUAL - - /** - * Override this to define Layout - */ - virtual BOOL Initialize() { return false; }; - virtual void UpdateLayout(); - -// Implementation -protected: - // Generated message map functions - //{{AFX_MSG(ETSLayoutDialogBar) - afx_msg void OnSize(UINT nType, int cx, int cy); - afx_msg void OnDestroy(); - afx_msg BOOL OnEraseBkgnd(CDC* pDC); - //}}AFX_MSG - LRESULT OnInitDialog(WPARAM, LPARAM); - DECLARE_MESSAGE_MAP() - - virtual CRect GetRect(); - bool m_bInitialized; -}; - - - -/************************************************** - ** ! the code is only tested for modal sheets ! ** - **************************************************/ - - -/** - * Resizable PropertySheet. Use this class standalone - * or as your base class (instead CProptertySheet) - */ -class ETSGUI_EXT_CLASS ETSLayoutPropertySheet : public CPropertySheet, protected ETSLayoutMgr -{ - DECLARE_DYNAMIC(ETSLayoutPropertySheet) - -// Construction -public: - ETSLayoutPropertySheet(UINT nIDCaption, CWnd *pParentWnd = NULL, UINT iSelectPage = 0, LPCTSTR strName=NULL, bool bGripper=true); - ETSLayoutPropertySheet(LPCTSTR pszCaption, CWnd *pParentWnd = NULL, UINT iSelectPage = 0, LPCTSTR strName=NULL, bool bGripper=true); - -// Operationen -public: - void SetAutoDestroy() { m_bAutoDestroy = true; } - void SetAutoDestroyPages() { m_bAutoDestroyPages = true; } - void ModelessWithButtons() { m_bModelessButtons = true; } -// Overrides - virtual void AddMainArea(CPane paneRoot, CPaneBase itemTab); - virtual void AddButtons(CPane paneBottom); - - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(ETSLayoutPropertySheet) - public: - virtual BOOL OnInitDialog(); - virtual void PostNcDestroy(); - //}}AFX_VIRTUAL - -// Implementation -public: - virtual ~ETSLayoutPropertySheet(); - - // Generated message map functions -protected: - //{{AFX_MSG(ETSLayoutPropertySheet) - afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); - afx_msg void OnSize(UINT nType, int cx, int cy); - afx_msg void OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI); - afx_msg void OnDestroy(); - afx_msg BOOL OnEraseBkgnd(CDC* pDC); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() - - void Resize(int cx, int cy); - -friend class ETSLayoutPropertyPage; - - void Init(LPCTSTR strName, bool bGripper); - CRect m_rcStart; - CRect m_rcPage; - bool m_bGripper; - CStatusBar m_StatusBar; - CPaneBase m_ItemTab; - bool m_bAutoDestroy; - bool m_bAutoDestroyPages; - bool m_bModelessButtons; -}; - -/** - * Base class for the Layout function. Derive your own class - * from this or derive it from CPropertyPage and - * modify _all_ references to CPropertyPage to - * ETSLayoutPropertyPage - */ -class ETSGUI_EXT_CLASS ETSLayoutPropertyPage : public ETSLayout::CBasePropertyPage, protected ETSLayoutMgr -{ -friend class ETSLayoutPropertySheet; - - DECLARE_DYNCREATE(ETSLayoutPropertyPage) - -// Konstruktion -public: - ETSLayoutPropertyPage( ); - ETSLayoutPropertyPage( UINT nIDTemplate, UINT nIDCaption = 0 ); - ETSLayoutPropertyPage( LPCTSTR lpszTemplateName, UINT nIDCaption = 0 ); - - ~ETSLayoutPropertyPage(); - - -// Overrides - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(ETSLayoutPropertyPage) - public: - virtual BOOL OnSetActive(); - //}}AFX_VIRTUAL - -// Implementation -protected: - // Generated message map functions - //{{AFX_MSG(ETSLayoutPropertyPage) - afx_msg void OnSize(UINT nType, int cx, int cy); - afx_msg void OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI); - virtual BOOL OnInitDialog(); - afx_msg BOOL OnEraseBkgnd(CDC* pDC); - afx_msg void OnWindowPosChanging( WINDOWPOS* lpwndpos ); - afx_msg void OnDestroy(); - afx_msg void OnWindowPosChanged(WINDOWPOS FAR* lpwndpos); - //}}AFX_MSG - DECLARE_MESSAGE_MAP() - - virtual CRect GetRect(); - bool m_bLockMove; - bool m_bResetBuddyOnNextTimeVisible; -}; - - - -//{{AFX_INSERT_LOCATION}} -// Microsoft Developer Studio will insert additional declarations immediately before the previous line. - -#endif // !defined(ETS_LAYOUTMGR_INCLUDED_) diff --git a/install/xbt/linux/misc/windows/browse_for_directory.cpp b/install/xbt/linux/misc/windows/browse_for_directory.cpp deleted file mode 100644 index 04010b571..000000000 --- a/install/xbt/linux/misc/windows/browse_for_directory.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "stdafx.h" -#include "browse_for_directory.h" - -int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData) -{ - if (uMsg == BFFM_INITIALIZED) - SendMessage(hwnd, BFFM_SETSELECTION, true, lpData); - return 0; -} - -int browse_for_directory(HWND hWnd, const std::string& title, std::string& directory) -{ - BROWSEINFO bi; - ZeroMemory(&bi, sizeof(BROWSEINFO)); - bi.hwndOwner = hWnd; - bi.lpszTitle = title.c_str(); - bi.ulFlags = BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS; - bi.lpfn = BrowseCallbackProc; - bi.lParam = reinterpret_cast(directory.c_str()); - ITEMIDLIST* idl = SHBrowseForFolder(&bi); - if (!idl) - return 1; - char path[MAX_PATH]; - if (!SHGetPathFromIDList(idl, path)) - *path = 0; - LPMALLOC lpm; - if (SHGetMalloc(&lpm) == NOERROR) - lpm->Free(idl); - if (!*path) - return 1; - directory = path; - return 0; -} \ No newline at end of file diff --git a/install/xbt/linux/misc/windows/browse_for_directory.h b/install/xbt/linux/misc/windows/browse_for_directory.h deleted file mode 100644 index bd275bd77..000000000 --- a/install/xbt/linux/misc/windows/browse_for_directory.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -int browse_for_directory(HWND, const std::string& title, std::string& directory); diff --git a/install/xbt/linux/misc/windows/nt_service.cpp b/install/xbt/linux/misc/windows/nt_service.cpp deleted file mode 100644 index 392f46c57..000000000 --- a/install/xbt/linux/misc/windows/nt_service.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "stdafx.h" -#include "nt_service.h" - -#include - -int nt_service_install(const char* name) -{ - SC_HANDLE scm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); - if (!scm) - return 1; - char file_name[MAX_PATH]; - GetModuleFileName(NULL, file_name, MAX_PATH); - SC_HANDLE service = CreateService(scm, - name, - name, - SERVICE_ALL_ACCESS, - SERVICE_WIN32_OWN_PROCESS, - SERVICE_AUTO_START, - SERVICE_ERROR_NORMAL, - file_name, - NULL, - NULL, - NULL, - "NT AUTHORITY\\LocalService", - NULL); - if (!service) - { - service = CreateService(scm, - name, - name, - SERVICE_ALL_ACCESS, - SERVICE_WIN32_OWN_PROCESS, - SERVICE_AUTO_START, - SERVICE_ERROR_NORMAL, - file_name, - NULL, - NULL, - NULL, - NULL, - NULL); - } - if (!service) - { - CloseServiceHandle(scm); - return 1; - } - CloseServiceHandle(service); - CloseServiceHandle(scm); - return 0; -} - -int nt_service_uninstall(const char* name) -{ - SC_HANDLE scm = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS); - if (!scm) - return 1; - int result = 1; - SC_HANDLE service = OpenService(scm, name, DELETE); - if (service) - { - if (DeleteService(service)) - result = 0; - CloseServiceHandle(service); - } - CloseServiceHandle(scm); - return result; -} diff --git a/install/xbt/linux/misc/windows/nt_service.h b/install/xbt/linux/misc/windows/nt_service.h deleted file mode 100644 index 0102ab78f..000000000 --- a/install/xbt/linux/misc/windows/nt_service.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once - -int nt_service_install(const char* name); -int nt_service_uninstall(const char* name); diff --git a/install/xbt/linux/misc/xbt/virtual_binary.h b/install/xbt/linux/misc/xbt/virtual_binary.h deleted file mode 100644 index b0d4ac09d..000000000 --- a/install/xbt/linux/misc/xbt/virtual_binary.h +++ /dev/null @@ -1,129 +0,0 @@ -#pragma once - -#include -#include -#include -#include -#include -#include - -class Cvirtual_binary_source: boost::noncopyable -{ -public: - Cvirtual_binary_source(const_memory_range); - - ~Cvirtual_binary_source() - { - delete[] m_range.begin; - } - - memory_range range() - { - return m_range; - } - - void resize(size_t v) - { - assert(v <= m_range.size()); - m_range.end = m_range.begin + v; - } -private: - memory_range m_range; -}; - -class Cvirtual_binary -{ -public: - int save(const std::string&) const; - int load(const std::string&); - Cvirtual_binary& load1(const std::string&); - void clear(); - size_t read(void* d) const; - unsigned char* write_start(size_t cb_d); - void write(const_memory_range); - Cvirtual_binary(size_t); - Cvirtual_binary(const_memory_range); - - Cvirtual_binary() - { - } - - const unsigned char* begin() const - { - return range().begin; - } - - unsigned char* mutable_begin() - { - return mutable_range().begin; - } - - const unsigned char* data() const - { - return range().begin; - } - - unsigned char* data_edit() - { - return mutable_range().begin; - } - - const unsigned char* end() const - { - return range().end; - } - - unsigned char* mutable_end() - { - return mutable_range().end; - } - - const_memory_range range() const - { - return m_source ? m_source->range() : memory_range(); - } - - memory_range mutable_range() - { - if (!m_source) - return memory_range(); - if (!m_source.unique()) - m_source = boost::make_shared(range()); - return m_source->range(); - } - - bool empty() const - { - return range().empty(); - } - - size_t size() const - { - return range().size(); - } - - void resize(size_t v) - { - if (!m_source) - write_start(v); - mutable_range(); - m_source->resize(v); - } - - operator const unsigned char*() const - { - return data(); - } - - operator const_memory_range() const - { - return range(); - } - - operator memory_range() - { - return mutable_range(); - } -private: - boost::shared_ptr m_source; -}; diff --git a/install/xbt/linux/misc/xcc_z.cpp b/install/xbt/linux/misc/xcc_z.cpp deleted file mode 100644 index 97bb10566..000000000 --- a/install/xbt/linux/misc/xcc_z.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "stdafx.h" -#include "xcc_z.h" - -#include -#include -#include -#include "stream_int.h" - -Cvirtual_binary xcc_z::gunzip(const_memory_range s) -{ - if (s.size() < 18) - return Cvirtual_binary(); - Cvirtual_binary d; - z_stream stream; - stream.zalloc = NULL; - stream.zfree = NULL; - stream.opaque = NULL; - stream.next_in = const_cast(s.begin) + 10; - stream.avail_in = s.size() - 18; - stream.next_out = d.write_start(read_int_le(4, s.end - 4)); - stream.avail_out = d.size(); - return stream.next_out - && Z_OK == inflateInit2(&stream, -MAX_WBITS) - && Z_STREAM_END == inflate(&stream, Z_FINISH) - && Z_OK == inflateEnd(&stream) - ? d - : Cvirtual_binary(); -} - -Cvirtual_binary xcc_z::gzip(const_memory_range s) -{ - Cvirtual_binary d; - unsigned long cb_d = s.size() + (s.size() + 999) / 1000 + 12; - unsigned char* w = d.write_start(10 + cb_d + 8); - *w++ = 0x1f; - *w++ = 0x8b; - *w++ = Z_DEFLATED; - *w++ = 0; - *w++ = 0; - *w++ = 0; - *w++ = 0; - *w++ = 0; - *w++ = 0; - *w++ = 3; - { - z_stream stream; - stream.zalloc = NULL; - stream.zfree = NULL; - stream.opaque = NULL; - deflateInit2(&stream, Z_DEFAULT_COMPRESSION, Z_DEFLATED, -MAX_WBITS, MAX_MEM_LEVEL, Z_DEFAULT_STRATEGY); - stream.next_in = const_cast(s.begin); - stream.avail_in = s.size(); - stream.next_out = w; - stream.avail_out = cb_d; - deflate(&stream, Z_FINISH); - deflateEnd(&stream); - w = stream.next_out; - } - w = write_int_le(4, w, crc32(crc32(0, NULL, 0), s, s.size())); - w = write_int_le(4, w, s.size()); - d.resize(w - d.data()); - return d; -} - -void xcc_z::gzip_out(const_memory_range s) -{ - gzFile f = gzdopen(fileno(stdout), "wb"); - gzwrite(f, const_cast(s.begin), s.size()); - gzflush(f, Z_FINISH); -} diff --git a/install/xbt/linux/misc/xcc_z.h b/install/xbt/linux/misc/xcc_z.h deleted file mode 100644 index 0d10e08ec..000000000 --- a/install/xbt/linux/misc/xcc_z.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include - -namespace xcc_z -{ - Cvirtual_binary gunzip(const_memory_range); - Cvirtual_binary gzip(const_memory_range); - void gzip_out(const_memory_range); -} diff --git a/install/xbt/linux/misc/xif_key.cpp b/install/xbt/linux/misc/xif_key.cpp deleted file mode 100644 index e90165e0d..000000000 --- a/install/xbt/linux/misc/xif_key.cpp +++ /dev/null @@ -1,196 +0,0 @@ -#include "stdafx.h" -#include "xif_key.h" - -#include -#include "stream_int.h" - -static int read_int(const byte*& r) -{ - r += 4; - return read_int_le(4, r - 4); -} - -void Cxif_key::load_old(const byte*& data) -{ - for (int count = read_int(data); count--; ) - { - Cxif_key& i = set_key(read_int(data)); - i.load_old(data); - } - for (int count = read_int(data); count--; ) - { - Cxif_value& i = set_value(read_int(data)); - i.load_old(data); - } -} - -void Cxif_key::load_new(const byte*& data) -{ - for (int count = read_int(data), id = 0; count--; ) - { - id += read_int(data); - open_key_write(id).load_new(data); - } - for (int count = read_int(data), id = 0; count--; ) - { - id += read_int(data); - open_value_write(id).load_new(data); - } -} - -void Cxif_key::load_external(const byte*& data) -{ - BOOST_FOREACH(t_xif_key_map::reference i, m_keys) - i.second.load_external(data); - BOOST_FOREACH(t_xif_value_map::reference i, m_values) - i.second.load_external(data); -} - -int Cxif_key::get_size() const -{ - int size = 8; - BOOST_FOREACH(t_xif_key_map::const_reference i, m_keys) - size += 4 + i.second.get_size(); - BOOST_FOREACH(t_xif_value_map::const_reference i, m_values) - { - size += 9; - switch (i.second.get_type()) - { - case vt_bin32: - case vt_int32: - break; - default: - if (!i.second.external_data()) - size += i.second.get_size(); - } - } - return size; -} - -int Cxif_key::get_external_size() const -{ - int size = 0; - BOOST_FOREACH(t_xif_key_map::const_reference i, m_keys) - size += i.second.get_external_size(); - BOOST_FOREACH(t_xif_value_map::const_reference i, m_values) - if (i.second.external_data()) - size += i.second.get_size(); - return size; -} - -void Cxif_key::save(byte*& data) const -{ - { - data = write_int_le(4, data, m_keys.size()); - int id = 0; - BOOST_FOREACH(t_xif_key_map::const_reference i, m_keys) - { - data = write_int_le(4, data, i.first - id); - id = i.first; - i.second.save(data); - } - } - { - data = write_int_le(4, data, m_values.size()); - int id = 0; - BOOST_FOREACH(t_xif_value_map::const_reference i, m_values) - { - data = write_int_le(4, data, i.first - id); - id = i.first; - i.second.save(data); - } - } -} - -void Cxif_key::external_save(byte*& data) const -{ - BOOST_FOREACH(t_xif_key_map::const_reference i, m_keys) - i.second.external_save(data); - BOOST_FOREACH(t_xif_value_map::const_reference i, m_values) - i.second.external_save(data); -} - -int Cxif_key::load_key(const byte* data, size_t size) -{ - const byte* read_p = data; - const t_xif_header_fast& header = *reinterpret_cast(read_p); - if (size < sizeof(t_xif_header_old) - || header.id != file_id - || header.version != file_version_old && header.version != file_version_new && header.version != file_version_fast) - return 1; - int error = 0; - if (header.version == file_version_old) - { - read_p += sizeof(t_xif_header_old) - 4; - load_old(read_p); - error = size != read_p - data; - } - else - { - unsigned long cb_d = header.size_uncompressed; - if (cb_d) - { - Cvirtual_binary d; - if (header.version == file_version_new) - error = Z_OK != uncompress(d.write_start(cb_d), &cb_d, data + sizeof(t_xif_header_old), size - sizeof(t_xif_header_old)); - else - error = Z_OK != uncompress(d.write_start(cb_d), &cb_d, data + sizeof(t_xif_header_fast), header.size_compressed); - if (!error) - { - read_p = d.data(); - load_new(read_p); - error = read_p != d.end(); - if (header.version == file_version_fast && !error) - { - read_p = data + sizeof(t_xif_header_fast) + header.size_compressed; - load_external(read_p); - error = size != read_p - data; - } - } - } - else - { - read_p = data + (header.version == file_version_fast ? sizeof(t_xif_header_fast) : sizeof(t_xif_header_old)); - load_new(read_p); - load_external(read_p); - error = size != read_p - data; - } - } - return error; -} - -Cvirtual_binary Cxif_key::vdata(bool fast) const -{ - Cvirtual_binary d; - int size = get_size(); - int external_size = get_external_size(); - if (fast) - { - t_xif_header_fast& header = *reinterpret_cast(d.write_start(sizeof(t_xif_header_fast) + size + external_size)); - header.id = file_id; - header.version = file_version_fast; - header.size_uncompressed = 0; - header.size_compressed = size; - header.size_external = external_size; - byte* w = d.data_edit() + sizeof(t_xif_header_fast); - save(w); - external_save(w); - assert(d.end() == w); - return d; - } - Cvirtual_binary s; - byte* w = s.write_start(size); - save(w); - unsigned long cb_d = s.size() + (s.size() + 999) / 1000 + 12; - t_xif_header_fast& header = *reinterpret_cast(d.write_start(sizeof(t_xif_header_fast) + cb_d + external_size)); - compress(d.data_edit() + sizeof(t_xif_header_fast), &cb_d, s.data(), s.size()); - w = d.data_edit() + sizeof(t_xif_header_fast) + cb_d; - external_save(w); - header.id = file_id; - header.version = file_version_fast; - header.size_uncompressed = size; - header.size_compressed = cb_d; - header.size_external = external_size; - d.resize(sizeof(t_xif_header_fast) + cb_d + external_size); - return d; -} diff --git a/install/xbt/linux/misc/xif_key.h b/install/xbt/linux/misc/xif_key.h deleted file mode 100644 index ea9fc4850..000000000 --- a/install/xbt/linux/misc/xif_key.h +++ /dev/null @@ -1,252 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -const static int file_id = 0x1a464958; // *reinterpret_cast("XIF\x1a"); -const static int file_version_old = 0; -const static int file_version_new = 1; -const static int file_version_fast = 2; - -struct t_xif_header_old -{ - int id; - int version; - int size_uncompressed; -}; - -struct t_xif_header_fast -{ - int id; - int version; - int size_uncompressed; - int size_compressed; - int size_external; -}; - -class Cxif_key; - -typedef std::map t_xif_key_map; -typedef std::map t_xif_value_map; - -class Cxif_key -{ -public: - Cxif_key(): - m_keys(*new t_xif_key_map) - { - } - - ~Cxif_key() - { - delete &m_keys; - } - - Cxif_key(const Cxif_key& v): - m_keys(*new t_xif_key_map) - { - m_keys = v.m_keys; - m_values = v.m_values; - } - - explicit Cxif_key(const Cvirtual_binary& v): - m_keys(*new t_xif_key_map) - { - load_key(v); - } - - const Cxif_key& operator=(const Cxif_key& v) - { - m_keys = v.m_keys; - m_values = v.m_values; - return *this; - } - - Cxif_key& set_key(int id) - { - m_keys[id] = Cxif_key(); - return m_keys[id]; - } - - const Cxif_key& open_key_read(int id) const - { - return m_keys.find(id)->second; - } - - Cxif_key& open_key_edit(int id) - { - return m_keys[id]; - } - - Cxif_key& open_key_write() - { - return open_key_write(m_keys.empty() ? 0 : m_keys.rbegin()->first + 1); - } - - Cxif_key& open_key_write(int id) - { - m_keys[id] = Cxif_key(); - return m_keys[id]; - } - - const Cxif_value& open_value_read(int id) const - { - return m_values.find(id)->second; - } - - Cxif_value& open_value_edit(int id) - { - return m_values[id]; - } - - Cxif_value& open_value_write(int id) - { - m_values[id] = Cxif_value(); - return m_values[id]; - } - - Cxif_value& set_value(int id) - { - m_values[id] = Cxif_value(); - return m_values[id]; - } - - void set_value_bin(int id, int v) - { - m_values[id] = Cxif_value(vt_bin32, v); - } - - void set_value_binary(int id, const Cvirtual_binary v, bool fast = false) - { - m_values[id] = Cxif_value(v, fast); - } - - void set_value_float(int id, float v) - { - m_values[id] = Cxif_value(v); - } - - void set_value_int(int id, int v) - { - m_values[id] = Cxif_value(vt_int32, v); - } - - void set_value_string(int id, const std::string& v) - { - m_values[id] = Cxif_value(v); - } - - void set_value_int64(int id, long long v) - { - set_value_binary(id, Cvirtual_binary(const_memory_range(&v, 8))); - } - - const Cxif_key& get_key(int id) const - { - static Cxif_key z; - t_xif_key_map::iterator i = m_keys.find(id); - return i == m_keys.end() ? z : i->second; - } - - const Cxif_value& get_value(int id) const - { - static Cxif_value z; - t_xif_value_map::const_iterator i = m_values.find(id); - return i == m_values.end() ? z : i->second; - } - - float get_value_float(int id) const - { - return get_value(id).get_float(); - } - - float get_value_float(int id, float v) const - { - return get_value(id).get_float(v); - } - - int get_value_int(int id) const - { - return get_value(id).get_int(); - } - - int get_value_int(int id, int v) const - { - return get_value(id).get_int(v); - } - - long long get_value_int64(int id) const - { - return *reinterpret_cast(get_value(id).get_data()); - } - - std::string get_value_string(int id) const - { - return get_value(id).get_string(); - } - - std::string get_value_string(int id, const std::string& v) const - { - return get_value(id).get_string(v); - } - - bool exists_key(int id) const - { - return m_keys.find(id) != m_keys.end(); - } - - bool exists_value(int id) const - { - return m_values.find(id) != m_values.end(); - } - - int c_keys() const - { - return m_keys.size(); - } - - int c_values() const - { - return m_values.size(); - } - - int load_key(const Cvirtual_binary& data) - { - return load_key(data.data(), data.size()); - } - - void delete_key(int id) - { - m_keys.erase(id); - } - - void delete_value(int id) - { - m_values.erase(id); - } - - void clear() - { - m_keys.clear(); - m_values.clear(); - } - - void dump(std::ostream& os, bool show_ratio, int depth = 0, Cvirtual_binary* t = NULL) const; - void dump_ratio(std::ostream& os, Cvirtual_binary* t) const; - Cvirtual_binary export_bz() const; - int load_key(const byte* data, size_t size); - Cvirtual_binary vdata(bool fast = false) const; - - t_xif_key_map& m_keys; - t_xif_value_map m_values; -private: - int get_size() const; - int get_external_size() const; - void load_old(const byte*& data); - void load_new(const byte*& data); - void load_external(const byte*& data); - void save(byte*& data) const; - void external_save(byte*& data) const; -}; diff --git a/install/xbt/linux/misc/xif_key_r.cpp b/install/xbt/linux/misc/xif_key_r.cpp deleted file mode 100644 index 58ee3db22..000000000 --- a/install/xbt/linux/misc/xif_key_r.cpp +++ /dev/null @@ -1,86 +0,0 @@ -#include "stdafx.h" -#include "xif_key_r.h" - -#include -#include -#include -#include - -static int read_int(const byte*& r) -{ - r += 4; - return read_int_le(4, r - 4); -} - -int Cxif_key_r::import(const_memory_range s) -{ - Cvirtual_binary d; - const t_xif_header_fast& h = *reinterpret_cast(s.begin); - if (s.size() < sizeof(t_xif_header_fast) + 8 - || h.id != file_id - || h.version != file_version_fast) - return 1; - unsigned long cb_d = h.size_uncompressed; - if (cb_d) - { - if (Z_OK != uncompress(d.write_start(cb_d), &cb_d, s + sizeof(t_xif_header_fast), h.size_compressed)) - return 1; - /* - if (uncompress(d.write_start(cb_d), &cb_d, s + sizeof(t_xif_header_fast), h.size_compressed) != Z_OK) - return 1; - */ - load(d); - // m_external_data = d + h.size_compressed; - } - else - { - load(s + sizeof(t_xif_header_fast)); - // m_external_data = s + sizeof(t_xif_header_fast) + h.size_uncompressed - } - - return 0; -} - -int Cxif_key_r::load(const byte* s) -{ - const byte* r = s; - { - int count = read_int(r); - int id = 0; - m_keys.reserve(count); - while (count--) - { - id += read_int(r); - m_keys.push_back(std::make_pair(id, Cxif_key_r())); - r += m_keys.rbegin()->second.load(r); - } - } - { - int count = read_int(r); - int id = 0; - m_values.reserve(count); - while (count--) - { - id += read_int(r); - m_values.push_back(std::make_pair(id, Cxif_value())); - m_values.rbegin()->second.load_new(r); - } - } - return r - s; -} - -Cxif_key_r::t_key_map::const_iterator Cxif_key_r::find_key(int id) const -{ - t_key_map::const_iterator i = keys().begin(); - while (i != keys().end() && i->first != id) - i++; - return i; -} - -Cxif_key_r::t_value_map::const_iterator Cxif_key_r::find_value(int id) const -{ - t_value_map::const_iterator i = values().begin(); - while (i != values().end() && i->first != id) - i++; - return i; -} diff --git a/install/xbt/linux/misc/xif_key_r.h b/install/xbt/linux/misc/xif_key_r.h deleted file mode 100644 index 690a253d3..000000000 --- a/install/xbt/linux/misc/xif_key_r.h +++ /dev/null @@ -1,97 +0,0 @@ -#pragma once - -#include -#include "xif_value.h" - -class Cxif_key_r -{ -public: - typedef std::vector > t_key_map; - typedef std::vector > t_value_map; - - const Cxif_key_r& get_key(int id) const - { - return find_key(id)->second; - } - - const Cxif_value& get_value(int id) const - { - static Cxif_value z; - t_value_map::const_iterator i = find_value(id); - return i == values().end() ? z : i->second; - } - - float get_value_float(int id) const - { - return get_value(id).get_float(); - } - - float get_value_float(int id, float v) const - { - return get_value(id).get_float(v); - } - - int get_value_int(int id) const - { - return get_value(id).get_int(); - } - - int get_value_int(int id, int v) const - { - return get_value(id).get_int(v); - } - - long long get_value_int64(int id) const - { - return *reinterpret_cast(get_value(id).get_data()); - } - - std::string get_value_string(int id) const - { - return get_value(id).get_string(); - } - - std::string get_value_string(int id, const std::string& v) const - { - return get_value(id).get_string(v); - } - - const t_key_map& keys() const - { - return m_keys; - } - - const t_value_map& values() const - { - return m_values; - } - - int c_keys() const - { - return keys().size(); - } - - int c_values() const - { - return values().size(); - } - - bool has_key(int id) const - { - return find_key(id) != keys().end(); - } - - bool has_value(int id) const - { - return find_value(id) != values().end(); - } - - t_key_map::const_iterator find_key(int id) const; - t_value_map::const_iterator find_value(int id) const; - int import(const_memory_range); -private: - int load(const byte* s); - - t_key_map m_keys; - t_value_map m_values; -}; diff --git a/install/xbt/linux/misc/xif_value.cpp b/install/xbt/linux/misc/xif_value.cpp deleted file mode 100644 index eceb9d6b9..000000000 --- a/install/xbt/linux/misc/xif_value.cpp +++ /dev/null @@ -1,151 +0,0 @@ -#include "stdafx.h" -#include "xif_value.h" - -#include -#include "stream_int.h" - -static float read_float(const byte*& r) -{ - assert(sizeof(float) == 4); - float v; - memcpy(&v, r, 4); - r += 4; - return v; -} - -static int read_int(const byte*& r) -{ - r += 4; - return read_int_le(4, r - 4); -} - -t_vt Cxif_value::get_type() const -{ - if (m_type != vt_unknown) - return m_type; - const byte* data = m_data.data(); - if (!data) - return vt_binary; - int size = m_data.size(); - if (!data[size - 1]) - { - const byte* r = data; - int c = size - 1; - while (c--) - { - if (*r != 9 && *r < 0x20) - break; - r++; - } - if (c == -1) - return vt_string; - } - if (size == 4) - return vt_int32; - return vt_binary; -} - -void Cxif_value::load_old(const byte*& data) -{ - m_data.clear(); - int size = read_int(data); - if (size == 4) - memcpy(m_value, data, size); - memcpy(m_data.write_start(size), data, size); - data += size; - m_type = vt_unknown; - m_type = get_type(); -} - -void Cxif_value::load_new(const byte*& data) -{ - m_data.clear(); - m_type = static_cast(*data++); - switch (m_type) - { - case vt_bin32: - case vt_int32: - m_value_int = read_int(data); - break; - case vt_float: - m_value_float = read_float(data); - break; - case vt_external_binary: - m_data.write_start(read_int(data)); - break; - default: - { - int size = read_int(data); - memcpy(m_data.write_start(size), data, size); - data += size; - } - } -} - -void Cxif_value::load_external(const byte*& data) -{ - if (!external_data()) - return; - memcpy(m_data.data_edit(), data, get_size()); - data += get_size(); -} - -int Cxif_value::skip(const byte* s) -{ - const byte* r = s; - t_vt type = static_cast(*r++); - switch (type) - { - case vt_bin32: - case vt_int32: - read_int(r); - break; - case vt_float: - read_float(r); - break; - case vt_external_binary: - read_int(r); - break; - default: - r += read_int(r); - } - return r - s; -} - -void Cxif_value::save(byte*& data) const -{ - *data++ = external_data() ? vt_external_binary : m_type; - switch (m_type) - { - case vt_bin32: - case vt_int32: - data = write_int_le(4, data, get_int()); - break; - case vt_float: - data = write_float(data, get_float()); - break; - default: - { - int size = get_size(); - data = write_int_le(4, data, size); - if (!external_data()) - { - memcpy(data, get_data(), size); - data += size; - } - } - } -} - -bool Cxif_value::external_data() const -{ - return m_type == vt_external_binary; -} - -void Cxif_value::external_save(byte*& data) const -{ - if (!external_data()) - return; - memcpy(data, get_data(), get_size()); - data += get_size(); -} diff --git a/install/xbt/linux/misc/xif_value.h b/install/xbt/linux/misc/xif_value.h deleted file mode 100644 index f248c2193..000000000 --- a/install/xbt/linux/misc/xif_value.h +++ /dev/null @@ -1,113 +0,0 @@ -#pragma once - -#include -#include - -enum t_vt {vt_bin32, vt_binary, vt_int32, vt_string, vt_external_binary, vt_float, vt_unknown}; - -class Cxif_value -{ -public: - Cxif_value() - { - m_type = vt_unknown; - } - - Cxif_value(float v) - { - m_type = vt_float; - m_value_float = v; - } - - Cxif_value(t_vt type, int v) - { - m_type = type; - m_value_int = v; - } - - Cxif_value(const Cvirtual_binary v, bool fast = false) - { - m_type = fast ? vt_external_binary : vt_binary; - m_data = v; - } - - Cxif_value(const std::string& v) - { - m_type = vt_string; - memcpy(m_data.write_start(v.length() + 1), v.c_str(), v.length() + 1); - } - - Cvirtual_binary get_vdata() const - { - assert(!idata()); - return m_data; - } - - const byte* get_data() const - { - return idata() ? m_value : m_data.data(); - } - - int get_size() const - { - return idata() ? 4 : m_data.size(); - } - - float get_float() const - { - assert(get_size() == 4); - return m_value_float; - } - - float get_float(float v) const - { - return get_size() ? get_float() : v; - } - - int get_int() const - { - assert(get_size() == 4); - return m_value_int; - } - - int get_int(int v) const - { - return get_size() ? get_int() : v; - } - - std::string get_string() const - { - assert(get_size()); - return reinterpret_cast(get_data()); - } - - std::string get_string(const std::string& v) const - { - return get_size() ? get_string() : v; - } - - bool idata() const - { - // internal data? - return get_type() == vt_bin32 || get_type() == vt_float || get_type() == vt_int32; - } - - void dump(std::ostream& os, int depth = 0) const; - t_vt get_type() const; - void load_old(const byte*& data); - void load_new(const byte*& data); - void load_external(const byte*& data); - void save(byte*& data) const; - static int skip(const byte* s); - bool external_data() const; - void external_save(byte*& data) const; -private: - Cvirtual_binary m_data; - t_vt m_type; - union - { - byte m_value[4]; - float m_value_float; - int m_value_int; - }; -}; diff --git a/install/xbt/windows/XBT Tracker.exe b/install/xbt/windows/XBT Tracker.exe deleted file mode 100644 index d6087c23e..000000000 Binary files a/install/xbt/windows/XBT Tracker.exe and /dev/null differ diff --git a/install/xbt/windows/htdocs/xbt.css b/install/xbt/windows/htdocs/xbt.css deleted file mode 100644 index 612de46ab..000000000 --- a/install/xbt/windows/htdocs/xbt.css +++ /dev/null @@ -1,5 +0,0 @@ -img {border-style: none;} -table {border-collapse: collapse;} -td, th {border: 1px solid #000000;} -td {background-color: #cccccc;} -th {background-color: #ccccff;} diff --git a/install/xbt/windows/htdocs/xbt_config.php b/install/xbt/windows/htdocs/xbt_config.php deleted file mode 100644 index 72402aa0d..000000000 --- a/install/xbt/windows/htdocs/xbt_config.php +++ /dev/null @@ -1,6 +0,0 @@ - - - -XBT Files -'); - printf('completed%d', $result['completed']); - printf('peers%d100 %%', $result['peers']); - if ($result['peers']) - { - printf('leechers%d%d %%', $result['leechers'], $result['leechers'] * 100 / $result['peers']); - printf('seeders%d%d %%', $result['seeders'], $result['seeders'] * 100 / $result['peers']); - } - printf('torrents%d', $result['torrents']); - printf('time%s', gmdate('Y-m-d H:i:s')); - echo(''); - echo('
'); - $results = mysql_query("select * from xbt_files where leechers or seeders order by ctime desc"); - echo(''); - echo(''); - echo(''); - printf('
fid'); - echo('info_hash'); - echo('leechers'); - echo('seeders'); - echo('completed'); - echo('modified'); - echo('created'); - while ($result = mysql_fetch_assoc($results)) - { - echo('
%d', $result['fid']); - printf('%s', bin2hex($result['info_hash'])); - echo(''); - if ($result['leechers']) - printf('%d', $result['leechers']); - echo(''); - if ($result['seeders']) - printf('%d', $result['seeders']); - echo(''); - if ($result['completed']) - printf('%d', $result['completed']); - printf('%s', gmdate('Y-m-d H:i:s', $result['mtime'])); - printf('%s', gmdate('Y-m-d H:i:s', $result['ctime'])); - } - echo('
'); -?> -
-
- XBT project at SF - Valid CSS! - Valid HTML 4.01! -
\ No newline at end of file diff --git a/install/xbt/windows/libmysql.dll b/install/xbt/windows/libmysql.dll deleted file mode 100644 index a80f347fc..000000000 Binary files a/install/xbt/windows/libmysql.dll and /dev/null differ diff --git a/install/xbt/windows/xbt_tracker.conf b/install/xbt/windows/xbt_tracker.conf deleted file mode 100644 index 81d394bb2..000000000 --- a/install/xbt/windows/xbt_tracker.conf +++ /dev/null @@ -1,47 +0,0 @@ -mysql_host = localhost -mysql_database = forum -mysql_user = user -mysql_password = user - -auto_register = 0 -anonymous_announce = 0 -anonymous_scrape = 0 -anonymous_connect = 0 -full_scrape = 0 -listen_check = 0 - -gzip_debug = 0 -gzip_scrape = 1 -full_scrape = 0 - -announce_interval = 700 -clean_up_interval = 60 -read_config_interval = 60 -read_db_interval = 150 -scrape_interval = 0 -write_db_interval = 3 -read_files_interval = 2 - -table_files = bb_bt_torrents -table_users = bb_bt_users -table_files_users = bb_bt_tracker - -column_files_completed = complete_count -column_files_fid = topic_id -column_users_uid = user_id - -column_users_can_leech = case when bt.u_down_total>5368709120 and (bt.u_up_total+bt.u_up_bonus)greatest(5368709120,bt.u_down_total) then 0 when bt.u_up_total>5368709120 and bt.u_down_total>0 then floor((bt.u_up_total+bt.u_up_bonus)/0.3/bt.u_down_total)+1 when (bt.u_up_total+bt.u_up_bonus)>bt.u_down_total then 3 else 2 end - -column_files_dl_percent = (select case tor.tor_type when 1 then 0 when 2 then 50 else 100 end from bb_bt_torrents tor where tor.topic_id=bt.topic_id) as dl_percent - -log_announce = 0 -gdc = 1 -debug = 0 -#free_leech = 0 -log_access = 0 - -redirect_url = http://site.ru/forum/ -trust_ipv6 = 1 -pid_file = F:/AnimeTracker/XBTT/xbt_tracker.pid - diff --git a/install/xbt/windows/zlibwapi.dll b/install/xbt/windows/zlibwapi.dll deleted file mode 100644 index 1c9092e7e..000000000 Binary files a/install/xbt/windows/zlibwapi.dll and /dev/null differ diff --git a/install/xbt/windows/Установка.txt b/install/xbt/windows/Установка.txt deleted file mode 100644 index af8e71d05..000000000 --- a/install/xbt/windows/Установка.txt +++ /dev/null @@ -1,2 +0,0 @@ -Открыть окно командной строки (Пуск - Выполнить - cmd). -Выполнить C:\путь до файла\"XBT Tracker".exe --install \ No newline at end of file diff --git a/install/xbt/xbt_tracker.conf b/install/xbt/xbt_tracker.conf deleted file mode 100644 index affea3aa7..000000000 --- a/install/xbt/xbt_tracker.conf +++ /dev/null @@ -1,47 +0,0 @@ -mysql_host = localhost -mysql_database = forum -mysql_user = user -mysql_password = user - -auto_register = 0 -anonymous_announce = 0 -anonymous_scrape = 0 -anonymous_connect = 0 -full_scrape = 0 -listen_check = 0 - -gzip_debug = 0 -gzip_scrape = 1 -full_scrape = 0 - -announce_interval = 700 -clean_up_interval = 60 -read_config_interval = 60 -read_db_interval = 150 -scrape_interval = 0 -write_db_interval = 3 -read_files_interval = 2 - -table_files = bb_bt_torrents -table_users = bb_bt_users -table_files_users = bb_bt_tracker - -column_files_completed = complete_count -column_files_fid = topic_id -column_users_uid = user_id - -column_users_can_leech = case when bt.u_down_total>5368709120 and (bt.u_up_total+bt.u_up_bonus)greatest(5368709120,bt.u_down_total) then 0 when bt.u_up_total>5368709120 and bt.u_down_total>0 then floor((bt.u_up_total+bt.u_up_bonus)/0.3/bt.u_down_total)+1 when (bt.u_up_total+bt.u_up_bonus)>bt.u_down_total then 3 else 2 end - -column_files_dl_percent = (select case tor.tor_type when 1 then 0 when 2 then 50 else 100 end from bb_bt_torrents tor where tor.topic_id=bt.topic_id) as dl_percent - -log_announce = 0 -gdc = 1 -debug = 0 -#free_leech = 0 -log_access = 0 - -redirect_url = http://site.ru/forum/ -trust_ipv6 = 1 -pid_file = xbt_tracker.pid - diff --git a/upload/ajax/view_profile.php b/upload/ajax/view_profile.php index 2c6cda510..373827f97 100644 --- a/upload/ajax/view_profile.php +++ b/upload/ajax/view_profile.php @@ -102,8 +102,7 @@ switch ($mode) $compl_size = ($rowset[$i]['remain'] && $rowset[$i]['size'] && $rowset[$i]['size'] > $rowset[$i]['remain']) ? ($rowset[$i]['size'] - $rowset[$i]['remain']) : 0; - if($bb_cfg['announce_type'] == 'xbt') $compl_perc = $rowset[$i]['complete_percent']; - else $compl_perc = ($compl_size) ? floor($compl_size * 100 / $rowset[$i]['size']) : 0; + $compl_perc = ($compl_size) ? floor($compl_size * 100 / $rowset[$i]['size']) : 0; $colspan = ''; $compl_perc_html = ''. $compl_perc .'%'; diff --git a/upload/attach_mod/displaying_torrent.php b/upload/attach_mod/displaying_torrent.php index 7c6f9ff92..ae651c42e 100644 --- a/upload/attach_mod/displaying_torrent.php +++ b/upload/attach_mod/displaying_torrent.php @@ -476,15 +476,8 @@ if ($tor_reged && $tor_info) $template->assign_block_vars("$x_full.porthead", array()); } } - $compl_size = ($peer['remain'] && $tor_size && $tor_size > $peer['remain']) ? ($tor_size - $peer['remain']) : 0; - if($bb_cfg['announce_type'] == 'xbt') - { - $compl_perc = $peer['complete_percent']; - } - else - { - $compl_perc = ($compl_size) ? floor($compl_size * 100 / $tor_size) : 0; - } + $compl_size = ($peer['remain'] && $tor_size && $tor_size > $peer['remain']) ? ($tor_size - $peer['remain']) : 0; + $compl_perc = ($compl_size) ? floor($compl_size * 100 / $tor_size) : 0; } $rel_sign = (!$guest && $peer['releaser']) ? ' ®' : ''; diff --git a/upload/attach_mod/includes/functions_delete.php b/upload/attach_mod/includes/functions_delete.php index 157ffc2c3..dd8f9468e 100644 --- a/upload/attach_mod/includes/functions_delete.php +++ b/upload/attach_mod/includes/functions_delete.php @@ -168,20 +168,6 @@ function delete_attachment($post_id_array = 0, $attach_id_array = 0, $page = 0, //bt if ($sql_id == 'post_id') { - // XBTT - if($bb_cfg['announce_type'] == 'xbt') - { - $sql = "INSERT INTO ". BB_BT_TORRENTS ."_del (topic_id, info_hash) - SELECT topic_id, info_hash - FROM ". BB_BT_TORRENTS ." - WHERE attach_id IN(". implode(',', $attach_id_array) .") ON DUPLICATE KEY UPDATE is_del=1"; - if ( !(DB()->sql_query($sql)) ) - { - message_die(GENERAL_ERROR, $lang['Error_deleted_attachments'], '', __LINE__, __FILE__, $sql); - } - } - // XBTT END. - $sql = "SELECT topic_id FROM ". BB_BT_TORRENTS ." WHERE attach_id IN(". implode(',', $attach_id_array) .")"; diff --git a/upload/bt/announce.php b/upload/bt/announce.php index b82081cbf..42be6f92b 100644 --- a/upload/bt/announce.php +++ b/upload/bt/announce.php @@ -4,13 +4,6 @@ define('IN_TRACKER', true); define('BB_ROOT', './../'); require(BB_ROOT .'common.php'); -if($bb_cfg['announce_type'] == 'xbt') -{ - $url = $bb_cfg['announce_xbt'] . str_replace('/bt/announce.php', '/announce', $_SERVER['REQUEST_URI']); - header("Location: $url"); - exit; -} - if (empty($_SERVER['HTTP_USER_AGENT'])) { header('Location: http://127.0.0.1', true, 301); diff --git a/upload/bt/scrape.php b/upload/bt/scrape.php index 20f50e786..1821161ef 100644 --- a/upload/bt/scrape.php +++ b/upload/bt/scrape.php @@ -6,13 +6,6 @@ require(BB_ROOT .'common.php'); if (!$tr_cfg['scrape']) msg_die('Please disable SCRAPE!'); -if($bb_cfg['announce_type'] == 'xbt') -{ - $url = $bb_cfg['announce_xbt'] . str_replace('/bt/scrape.php', '/scrape', $_SERVER['REQUEST_URI']); - header("Location: $url"); - exit; -} - // Recover info_hash if (isset($_GET['?info_hash']) && !isset($_GET['info_hash'])) { diff --git a/upload/config.php b/upload/config.php index c1d39b31e..1f2dbe625 100644 --- a/upload/config.php +++ b/upload/config.php @@ -55,8 +55,8 @@ $domain_name = (!empty($_SERVER['SERVER_NAME'])) ? $_SERVER['SERVER_NAME'] : $do // Increase number of revision after update $bb_cfg['tp_version'] = '2.5 (unstable)'; -$bb_cfg['tp_release_date'] = '30-08-2013'; -$bb_cfg['tp_release_state'] = 'R549'; +$bb_cfg['tp_release_date'] = '02-09-2013'; +$bb_cfg['tp_release_state'] = 'R551'; // Database $charset = 'utf8'; @@ -123,8 +123,6 @@ $bb_cfg['site_backup_shell_cmd'] = ''; $bb_cfg['gzip_compress'] = true; // compress output // Tracker -$bb_cfg['announce_type'] = 'php'; // Тип анонсера, xbt или php -$bb_cfg['announce_xbt'] = "http://{$domain_name}:2710"; $bb_cfg['announce_interval'] = 2400; // Announce interval (default: 1800) $bb_cfg['passkey_key'] = 'uk'; // Passkey key name in GET request $bb_cfg['ignore_reported_ip'] = false; // Ignore IP reported by client diff --git a/upload/dl_list.php b/upload/dl_list.php index f316dfe10..8a0ad03b7 100644 --- a/upload/dl_list.php +++ b/upload/dl_list.php @@ -175,14 +175,7 @@ if ($topics_ary && ($mode == 'set_dl_status' || $mode == 'set_topics_dl_status') AND topic_id IN(". join(',', $topics_ary) .") "); - if ($bb_cfg['announce_type'] == 'xbt') - { - DB()->query("REPLACE INTO ". BB_BT_DLSTATUS_MAIN ." $new_dlstatus_sql"); - } - else - { - DB()->query("REPLACE INTO ". BB_BT_DLSTATUS_NEW ." $new_dlstatus_sql"); - } + DB()->query("REPLACE INTO ". BB_BT_DLSTATUS_NEW ." $new_dlstatus_sql"); redirect("$redirect_type?$redirect"); } diff --git a/upload/includes/cron/jobs/clean_dlstat.php b/upload/includes/cron/jobs/clean_dlstat.php index fbcbb6a25..a2ee01b11 100644 --- a/upload/includes/cron/jobs/clean_dlstat.php +++ b/upload/includes/cron/jobs/clean_dlstat.php @@ -2,47 +2,44 @@ if (!defined('BB_ROOT')) die(basename(__FILE__)); -if($bb_cfg['announce_type'] != 'xbt') -{ - define('BUF_DLSTATUS_TABLE', 'tmp_buf_dlstatus'); +define('BUF_DLSTATUS_TABLE', 'tmp_buf_dlstatus'); - // Move new dl-status records to main table - DB()->query(" - CREATE TEMPORARY TABLE ". BUF_DLSTATUS_TABLE ." ( - user_id mediumint(9) NOT NULL default '0', - topic_id mediumint(8) unsigned NOT NULL default '0', - user_status tinyint(1) NOT NULL default '0', - PRIMARY KEY (user_id, topic_id) - ) ENGINE = MyISAM - "); +// Move new dl-status records to main table +DB()->query(" + CREATE TEMPORARY TABLE ". BUF_DLSTATUS_TABLE ." ( + user_id mediumint(9) NOT NULL default '0', + topic_id mediumint(8) unsigned NOT NULL default '0', + user_status tinyint(1) NOT NULL default '0', + PRIMARY KEY (user_id, topic_id) + ) ENGINE = MyISAM +"); - DB()->query(" - INSERT INTO ". BUF_DLSTATUS_TABLE ." - (user_id, topic_id, user_status) - SELECT - user_id, topic_id, user_status - FROM - ". BB_BT_DLSTATUS_NEW ." - WHERE - last_modified_dlstatus < DATE_SUB(NOW(), INTERVAL 1 DAY) - "); +DB()->query(" + INSERT INTO ". BUF_DLSTATUS_TABLE ." + (user_id, topic_id, user_status) + SELECT + user_id, topic_id, user_status + FROM + ". BB_BT_DLSTATUS_NEW ." + WHERE + last_modified_dlstatus < DATE_SUB(NOW(), INTERVAL 1 DAY) +"); - DB()->query(" - REPLACE INTO ". BB_BT_DLSTATUS_MAIN ." - (user_id, topic_id, user_status) - SELECT - user_id, topic_id, user_status - FROM ". BUF_DLSTATUS_TABLE ." - "); +DB()->query(" + REPLACE INTO ". BB_BT_DLSTATUS_MAIN ." + (user_id, topic_id, user_status) + SELECT + user_id, topic_id, user_status + FROM ". BUF_DLSTATUS_TABLE ." +"); - DB()->query(" - DELETE new - FROM ". BUF_DLSTATUS_TABLE ." buf - INNER JOIN ". BB_BT_DLSTATUS_NEW ." new USING(user_id, topic_id) - "); +DB()->query(" + DELETE new + FROM ". BUF_DLSTATUS_TABLE ." buf + INNER JOIN ". BB_BT_DLSTATUS_NEW ." new USING(user_id, topic_id) +"); - DB()->query("DROP TEMPORARY TABLE ". BUF_DLSTATUS_TABLE); -} +DB()->query("DROP TEMPORARY TABLE ". BUF_DLSTATUS_TABLE); // Delete staled dl-status records $keeping_dlstat = array( @@ -119,4 +116,4 @@ DB()->query(" up_release_today = 0, up_bonus_today = 0, points_today = 0 -"); +"); \ No newline at end of file diff --git a/upload/includes/cron/jobs/tr_cleanup_and_dlstat.php b/upload/includes/cron/jobs/tr_cleanup_and_dlstat.php index 64b65d989..d38e2b3a1 100644 --- a/upload/includes/cron/jobs/tr_cleanup_and_dlstat.php +++ b/upload/includes/cron/jobs/tr_cleanup_and_dlstat.php @@ -6,49 +6,46 @@ global $tr_cfg; $releaser = DL_STATUS_RELEASER; -if($bb_cfg['announce_type'] != 'xbt') +define('NEW_BB_BT_LAST_TORSTAT', 'new_bt_last_torstat'); +define('OLD_BB_BT_LAST_TORSTAT', 'old_bt_last_torstat'); +define('NEW_BB_BT_LAST_USERSTAT', 'new_bt_last_userstat'); +define('OLD_BB_BT_LAST_USERSTAT', 'old_bt_last_userstat'); + +DB()->query("DROP TABLE IF EXISTS ". NEW_BB_BT_LAST_TORSTAT .", ". NEW_BB_BT_LAST_USERSTAT); +DB()->query("DROP TABLE IF EXISTS ". OLD_BB_BT_LAST_TORSTAT .", ". OLD_BB_BT_LAST_USERSTAT); + +DB()->query("CREATE TABLE ". NEW_BB_BT_LAST_TORSTAT ." LIKE ". BB_BT_LAST_TORSTAT); +DB()->query("CREATE TABLE ". NEW_BB_BT_LAST_USERSTAT ." LIKE ". BB_BT_LAST_USERSTAT); + +DB()->expect_slow_query(600); + +// Update dlstat (part 1) +if ($tr_cfg['update_dlstat']) { - define('NEW_BB_BT_LAST_TORSTAT', 'new_bt_last_torstat'); - define('OLD_BB_BT_LAST_TORSTAT', 'old_bt_last_torstat'); - define('NEW_BB_BT_LAST_USERSTAT', 'new_bt_last_userstat'); - define('OLD_BB_BT_LAST_USERSTAT', 'old_bt_last_userstat'); + // ############################ Tables LOCKED ################################ + DB()->lock(array( + BB_BT_TRACKER, + NEW_BB_BT_LAST_TORSTAT, + )); - DB()->query("DROP TABLE IF EXISTS ". NEW_BB_BT_LAST_TORSTAT .", ". NEW_BB_BT_LAST_USERSTAT); - DB()->query("DROP TABLE IF EXISTS ". OLD_BB_BT_LAST_TORSTAT .", ". OLD_BB_BT_LAST_USERSTAT); + // Get PER TORRENT user's dlstat from tracker + DB()->query(" + INSERT INTO ". NEW_BB_BT_LAST_TORSTAT ." + (topic_id, user_id, dl_status, up_add, down_add, release_add, speed_up, speed_down) + SELECT + topic_id, user_id, IF(releaser, $releaser, seeder), SUM(up_add), SUM(down_add), IF(releaser, SUM(up_add), 0), SUM(speed_up), SUM(speed_down) + FROM ". BB_BT_TRACKER ." + WHERE (up_add != 0 OR down_add != 0) + GROUP BY topic_id, user_id + "); - DB()->query("CREATE TABLE ". NEW_BB_BT_LAST_TORSTAT ." LIKE ". BB_BT_LAST_TORSTAT); - DB()->query("CREATE TABLE ". NEW_BB_BT_LAST_USERSTAT ." LIKE ". BB_BT_LAST_USERSTAT); - - DB()->expect_slow_query(600); - - // Update dlstat (part 1) - if ($tr_cfg['update_dlstat']) - { - // ############################ Tables LOCKED ################################ - DB()->lock(array( - BB_BT_TRACKER, - NEW_BB_BT_LAST_TORSTAT, - )); - - // Get PER TORRENT user's dlstat from tracker - DB()->query(" - INSERT INTO ". NEW_BB_BT_LAST_TORSTAT ." - (topic_id, user_id, dl_status, up_add, down_add, release_add, speed_up, speed_down) - SELECT - topic_id, user_id, IF(releaser, $releaser, seeder), SUM(up_add), SUM(down_add), IF(releaser, SUM(up_add), 0), SUM(speed_up), SUM(speed_down) - FROM ". BB_BT_TRACKER ." - WHERE (up_add != 0 OR down_add != 0) - GROUP BY topic_id, user_id - "); - - // Reset up/down additions in tracker - DB()->query("UPDATE ". BB_BT_TRACKER ." SET up_add = 0, down_add = 0"); - - DB()->unlock(); - // ############################ Tables UNLOCKED ############################## - } + // Reset up/down additions in tracker + DB()->query("UPDATE ". BB_BT_TRACKER ." SET up_add = 0, down_add = 0"); + DB()->unlock(); + // ############################ Tables UNLOCKED ############################## } + // Update last seeder info in BUF DB()->query(" REPLACE INTO ". BUF_LAST_SEEDER ." @@ -70,123 +67,97 @@ if ($tr_cfg['autoclean']) DB()->query("DELETE FROM ". BB_BT_TRACKER ." WHERE update_time < $peer_expire_time"); } -if($bb_cfg['announce_type'] == 'xbt') +// Update dlstat (part 2) +if ($tr_cfg['update_dlstat']) { + // Set "only 1 seeder" bonus + DB()->query(" + UPDATE + ". NEW_BB_BT_LAST_TORSTAT ." tb, + ". BB_BT_TRACKER_SNAP ." sn + SET + tb.bonus_add = tb.up_add + WHERE + tb.topic_id = sn.topic_id + AND sn.seeders = 1 + AND tb.up_add != 0 + AND tb.dl_status = ". DL_STATUS_COMPLETE ." + "); + + // Get SUMMARIZED user's dlstat + DB()->query(" + INSERT INTO ". NEW_BB_BT_LAST_USERSTAT ." + (user_id, up_add, down_add, release_add, bonus_add, speed_up, speed_down) + SELECT + user_id, SUM(up_add), SUM(down_add), SUM(release_add), SUM(bonus_add), SUM(speed_up), SUM(speed_down) + FROM ". NEW_BB_BT_LAST_TORSTAT ." + GROUP BY user_id + "); + + // Update TOTAL user's dlstat + DB()->query(" + UPDATE + ". BB_BT_USERS ." u, + ". NEW_BB_BT_LAST_USERSTAT ." ub + SET + u.u_up_total = u.u_up_total + ub.up_add, + u.u_down_total = u.u_down_total + ub.down_add, + u.u_up_release = u.u_up_release + ub.release_add, + u.u_up_bonus = u.u_up_bonus + ub.bonus_add, + u.up_today = u.up_today + ub.up_add, + u.down_today = u.down_today + ub.down_add, + u.up_release_today = u.up_release_today + ub.release_add, + u.up_bonus_today = u.up_bonus_today + ub.bonus_add + WHERE u.user_id = ub.user_id + "); + + // Delete from MAIN what exists in BUF but not exsits in NEW + DB()->query(" + DELETE main + FROM ". BB_BT_DLSTATUS_MAIN ." main + INNER JOIN ( + ". NEW_BB_BT_LAST_TORSTAT ." buf + LEFT JOIN ". BB_BT_DLSTATUS_NEW ." new USING(user_id, topic_id) + ) USING(user_id, topic_id) + WHERE new.user_id IS NULL + AND new.topic_id IS NULL + "); + + // Update DL-Status + DB()->query(" + REPLACE INTO ". BB_BT_DLSTATUS_NEW ." + (user_id, topic_id, user_status) + SELECT + user_id, topic_id, dl_status + FROM ". NEW_BB_BT_LAST_TORSTAT ." + "); + + // Update PER TORRENT DL-Status (for "completed" counter) DB()->query(" INSERT IGNORE INTO ". BB_BT_TORSTAT ." (topic_id, user_id) SELECT topic_id, user_id - FROM ". BB_BT_TRACKER ." - WHERE IF(releaser, $releaser, seeder) = ". DL_STATUS_COMPLETE ." AND (up_add != 0 OR down_add != 0) + FROM ". NEW_BB_BT_LAST_TORSTAT ." + WHERE dl_status = ". DL_STATUS_COMPLETE ." "); - // Reset up/down additions in tracker - DB()->query("UPDATE ". BB_BT_TRACKER ." SET up_add = 0, down_add = 0"); } -// Delete not registered torrents from tracker -/* + DB()->query(" - DELETE tr - FROM ". BB_BT_TRACKER ." tr - LEFT JOIN ". BB_BT_TORRENTS ." tor USING(topic_id) - WHERE tor.topic_id IS NULL + RENAME TABLE + ". BB_BT_LAST_TORSTAT ." TO ". OLD_BB_BT_LAST_TORSTAT .", + ". NEW_BB_BT_LAST_TORSTAT ." TO ". BB_BT_LAST_TORSTAT ." "); -*/ +DB()->query("DROP TABLE IF EXISTS ". NEW_BB_BT_LAST_TORSTAT .", ". OLD_BB_BT_LAST_TORSTAT); -if($bb_cfg['announce_type'] != 'xbt') -{ - // Update dlstat (part 2) - if ($tr_cfg['update_dlstat']) - { - // Set "only 1 seeder" bonus - DB()->query(" - UPDATE - ". NEW_BB_BT_LAST_TORSTAT ." tb, - ". BB_BT_TRACKER_SNAP ." sn - SET - tb.bonus_add = tb.up_add - WHERE - tb.topic_id = sn.topic_id - AND sn.seeders = 1 - AND tb.up_add != 0 - AND tb.dl_status = ". DL_STATUS_COMPLETE ." - "); +DB()->query(" + RENAME TABLE + ". BB_BT_LAST_USERSTAT ." TO ". OLD_BB_BT_LAST_USERSTAT .", + ". NEW_BB_BT_LAST_USERSTAT ." TO ". BB_BT_LAST_USERSTAT ." +"); +DB()->query("DROP TABLE IF EXISTS ". NEW_BB_BT_LAST_USERSTAT .", ". OLD_BB_BT_LAST_USERSTAT); - // Get SUMMARIZED user's dlstat - DB()->query(" - INSERT INTO ". NEW_BB_BT_LAST_USERSTAT ." - (user_id, up_add, down_add, release_add, bonus_add, speed_up, speed_down) - SELECT - user_id, SUM(up_add), SUM(down_add), SUM(release_add), SUM(bonus_add), SUM(speed_up), SUM(speed_down) - FROM ". NEW_BB_BT_LAST_TORSTAT ." - GROUP BY user_id - "); - - // Update TOTAL user's dlstat - DB()->query(" - UPDATE - ". BB_BT_USERS ." u, - ". NEW_BB_BT_LAST_USERSTAT ." ub - SET - u.u_up_total = u.u_up_total + ub.up_add, - u.u_down_total = u.u_down_total + ub.down_add, - u.u_up_release = u.u_up_release + ub.release_add, - u.u_up_bonus = u.u_up_bonus + ub.bonus_add, - u.up_today = u.up_today + ub.up_add, - u.down_today = u.down_today + ub.down_add, - u.up_release_today = u.up_release_today + ub.release_add, - u.up_bonus_today = u.up_bonus_today + ub.bonus_add - WHERE u.user_id = ub.user_id - "); - - // Delete from MAIN what exists in BUF but not exsits in NEW - DB()->query(" - DELETE main - FROM ". BB_BT_DLSTATUS_MAIN ." main - INNER JOIN ( - ". NEW_BB_BT_LAST_TORSTAT ." buf - LEFT JOIN ". BB_BT_DLSTATUS_NEW ." new USING(user_id, topic_id) - ) USING(user_id, topic_id) - WHERE new.user_id IS NULL - AND new.topic_id IS NULL - "); - - // Update DL-Status - DB()->query(" - REPLACE INTO ". BB_BT_DLSTATUS_NEW ." - (user_id, topic_id, user_status) - SELECT - user_id, topic_id, dl_status - FROM ". NEW_BB_BT_LAST_TORSTAT ." - "); - - // Update PER TORRENT DL-Status (for "completed" counter) - DB()->query(" - INSERT IGNORE INTO ". BB_BT_TORSTAT ." - (topic_id, user_id) - SELECT - topic_id, user_id - FROM ". NEW_BB_BT_LAST_TORSTAT ." - WHERE dl_status = ". DL_STATUS_COMPLETE ." - "); - } - - DB()->query(" - RENAME TABLE - ". BB_BT_LAST_TORSTAT ." TO ". OLD_BB_BT_LAST_TORSTAT .", - ". NEW_BB_BT_LAST_TORSTAT ." TO ". BB_BT_LAST_TORSTAT ." - "); - DB()->query("DROP TABLE IF EXISTS ". NEW_BB_BT_LAST_TORSTAT .", ". OLD_BB_BT_LAST_TORSTAT); - - DB()->query(" - RENAME TABLE - ". BB_BT_LAST_USERSTAT ." TO ". OLD_BB_BT_LAST_USERSTAT .", - ". NEW_BB_BT_LAST_USERSTAT ." TO ". BB_BT_LAST_USERSTAT ." - "); - DB()->query("DROP TABLE IF EXISTS ". NEW_BB_BT_LAST_USERSTAT .", ". OLD_BB_BT_LAST_USERSTAT); - - DB()->expect_slow_query(10); -} +DB()->expect_slow_query(10); if($bb_cfg['seed_bonus_enabled'] && $bb_cfg['seed_bonus_points'] && $bb_cfg['seed_bonus_release']) { diff --git a/upload/includes/cron/jobs/tr_make_snapshot.php b/upload/includes/cron/jobs/tr_make_snapshot.php index b28c706ed..43cecde1f 100644 --- a/upload/includes/cron/jobs/tr_make_snapshot.php +++ b/upload/includes/cron/jobs/tr_make_snapshot.php @@ -64,39 +64,37 @@ DB()->query(" DB()->query("DROP TABLE IF EXISTS ". NEW_BB_BT_TRACKER_SNAP .", ". OLD_BB_BT_TRACKER_SNAP); -if($bb_cfg['announce_type'] != 'xbt') +// +// Make dl-list snapshot +// +define('NEW_BB_BT_DLSTATUS_SNAP', 'new_dlstatus_snap'); +define('OLD_BB_BT_DLSTATUS_SNAP', 'old_dlstatus_snap'); + +DB()->query("DROP TABLE IF EXISTS ". NEW_BB_BT_DLSTATUS_SNAP .", ". OLD_BB_BT_DLSTATUS_SNAP); + +DB()->query("CREATE TABLE ". NEW_BB_BT_DLSTATUS_SNAP ." LIKE ". BB_BT_DLSTATUS_SNAP); + +if ($bb_cfg['bt_show_dl_list'] && $bb_cfg['bt_dl_list_only_count']) { - // - // Make dl-list snapshot - // - define('NEW_BB_BT_DLSTATUS_SNAP', 'new_dlstatus_snap'); - define('OLD_BB_BT_DLSTATUS_SNAP', 'old_dlstatus_snap'); - - DB()->query("DROP TABLE IF EXISTS ". NEW_BB_BT_DLSTATUS_SNAP .", ". OLD_BB_BT_DLSTATUS_SNAP); - - DB()->query("CREATE TABLE ". NEW_BB_BT_DLSTATUS_SNAP ." LIKE ". BB_BT_DLSTATUS_SNAP); - - if ($bb_cfg['bt_show_dl_list'] && $bb_cfg['bt_dl_list_only_count']) - { - DB()->query(" - INSERT INTO ". NEW_BB_BT_DLSTATUS_SNAP ." - (topic_id, dl_status, users_count) - SELECT - topic_id, user_status, COUNT(*) - FROM ". BB_BT_DLSTATUS ." - WHERE user_status != ". DL_STATUS_RELEASER ." - GROUP BY topic_id, user_status - "); - } - DB()->query(" - RENAME TABLE - ". BB_BT_DLSTATUS_SNAP ." TO ". OLD_BB_BT_DLSTATUS_SNAP .", - ". NEW_BB_BT_DLSTATUS_SNAP ." TO ". BB_BT_DLSTATUS_SNAP ." + INSERT INTO ". NEW_BB_BT_DLSTATUS_SNAP ." + (topic_id, dl_status, users_count) + SELECT + topic_id, user_status, COUNT(*) + FROM ". BB_BT_DLSTATUS ." + WHERE user_status != ". DL_STATUS_RELEASER ." + GROUP BY topic_id, user_status "); - - DB()->query("DROP TABLE IF EXISTS ". NEW_BB_BT_DLSTATUS_SNAP .", ". OLD_BB_BT_DLSTATUS_SNAP); } + +DB()->query(" + RENAME TABLE + ". BB_BT_DLSTATUS_SNAP ." TO ". OLD_BB_BT_DLSTATUS_SNAP .", + ". NEW_BB_BT_DLSTATUS_SNAP ." TO ". BB_BT_DLSTATUS_SNAP ." +"); + +DB()->query("DROP TABLE IF EXISTS ". NEW_BB_BT_DLSTATUS_SNAP .", ". OLD_BB_BT_DLSTATUS_SNAP); + // // TORHELP // diff --git a/upload/includes/functions.php b/upload/includes/functions.php index eb16769dd..303406a24 100644 --- a/upload/includes/functions.php +++ b/upload/includes/functions.php @@ -2672,17 +2672,8 @@ function create_magnet($infohash, $auth_key, $logged_in) { global $bb_cfg, $_GET, $userdata, $images; - if ($bb_cfg['announce_type'] == 'xbt') - { - $passkey = substr('00000000'. dechex($userdata['user_id']), -8) . substr(sha1($bb_cfg['torrent_pass_private_key'] .' '. $auth_key .' '. $userdata['user_id'] .' '. $infohash), 0, 24); - $announce = $bb_cfg['announce_xbt'] .'/'. $passkey .'/announce'; - return ''; - } - else - { - $passkey_url = ((!$logged_in || isset($_GET['no_passkey'])) && $bb_cfg['bt_tor_browse_only_reg']) ? '' : "?{$bb_cfg['passkey_key']}=$auth_key"; - return ''; - } + $passkey_url = ((!$logged_in || isset($_GET['no_passkey'])) && $bb_cfg['bt_tor_browse_only_reg']) ? '' : "?{$bb_cfg['passkey_key']}=$auth_key"; + return ''; } function get_avatar ($avatar, $type, $allow_avatar = true, $height = '', $width = '') diff --git a/upload/includes/functions_torrent.php b/upload/includes/functions_torrent.php index 82ff12989..c23e46341 100644 --- a/upload/includes/functions_torrent.php +++ b/upload/includes/functions_torrent.php @@ -110,20 +110,6 @@ function tracker_unregister ($attach_id, $mode = '') } } - // XBTT - if ($bb_cfg['announce_type'] == 'xbt') - { - $sql = "INSERT INTO ". BB_BT_TORRENTS ."_del(topic_id, info_hash) - SELECT topic_id, info_hash - FROM ". BB_BT_TORRENTS ." - WHERE attach_id = $attach_id ON DUPLICATE KEY UPDATE is_del=1"; - - if (!DB()->sql_query($sql)) - { - message_die(GENERAL_ERROR, 'Could not delete torrent from torrents table', '', __LINE__, __FILE__, $sql); - } - } - // Remove peers from tracker $sql = "DELETE FROM ". BB_BT_TRACKER ." WHERE topic_id = $topic_id"; @@ -224,20 +210,6 @@ function change_tor_type ($attach_id, $tor_status_gold) $topic_id = $torrent['topic_id']; $tor_status_gold = intval($tor_status_gold); DB()->query("UPDATE ". BB_BT_TORRENTS ." SET tor_type = $tor_status_gold WHERE topic_id = $topic_id LIMIT 1"); - - // XBTT - if ($bb_cfg['announce_type'] == 'xbt') - { - $sql = "SELECT CASE tor_type WHEN 1 THEN 0 WHEN 2 THEN 50 ELSE 100 END AS dl_percent, topic_id, info_hash FROM ". BB_BT_TORRENTS ." WHERE topic_id = $topic_id"; - $result = DB()->query($sql); - $row = DB()->sql_fetchrow($result); - $sql = "INSERT INTO ". BB_BT_TORRENTS ."_del(is_del, topic_id,info_hash, dl_percent) - VALUES (0, " .$row['topic_id'] .", '". DB()->escape($row['info_hash']) ."', ". $row['dl_percent'] .") ON DUPLICATE KEY UPDATE dl_percent = values(dl_percent)"; - if (!DB()->sql_query($sql)) - { - message_die(GENERAL_ERROR, "Error delete_torrents", '', __LINE__, __FILE__, $sql); - } - } } function tracker_register ($attach_id, $mode = '', $tor_status = TOR_NOT_APPROVED) @@ -548,17 +520,7 @@ function send_torrent_with_passkey ($filename) message_die(GENERAL_ERROR, 'This is not a bencoded file'); } - // XBTT unique passkey - if ($bb_cfg['announce_type'] == 'xbt') - { - $info_hash = pack('H*', sha1(bencode($tor['info']))); - $passkey = substr('00000000'. dechex($userdata['user_id']), -8) . substr(sha1($bb_cfg['torrent_pass_private_key'] .' '. $passkey_val .' '. $userdata['user_id'] .' '. $info_hash), 0, 24); - $announce = $bb_cfg['announce_xbt'] .'/'. $passkey .'/announce'; - } - else - { - $announce = strval($ann_url . "?$passkey_key=$passkey_val"); - } + $announce = strval($ann_url . "?$passkey_key=$passkey_val"); // Replace original announce url with tracker default if ($bb_cfg['bt_replace_ann_url'] || !@$tor['announce'])