Отказ от поддержки XBT Tracker. Подробности на форуме: http://torrentpier.me/threads/13574/ git-svn-id: https://torrentpier2.googlecode.com/svn/trunk@551 a8ac35ab-4ca4-ca47-4c2d-a49a94f06293
This commit is contained in:
glix08 2013-09-02 19:33:32 +00:00
commit 47ac552653
108 changed files with 185 additions and 14265 deletions

View file

@ -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;

View file

@ -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)

View file

@ -1,135 +0,0 @@
#include "stdafx.h"
#include <windows/nt_service.h>
#include <iostream>
#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<int>(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();
}

View file

@ -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

View file

@ -1,3 +0,0 @@
#include "resource.h"
IDR_MAINFRAME ICON "res\\XBT Tracker.ico"

View file

@ -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

View file

@ -1,709 +0,0 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9,00"
Name="XBT Tracker"
ProjectGUID="{73C570AC-E7C3-451D-A5C6-7A2532F0121B}"
RootNamespace="XBT Tracker"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
InheritedPropertySheets="..\XBT.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
WholeProgramOptimization="true"
AdditionalIncludeDirectories="..\misc"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
StringPooling="true"
RuntimeLibrary="0"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="stdafx.h"
WarningLevel="3"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="NDEBUG"
Culture="1043"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="zlib.lib"
LinkIncremental="1"
SubSystem="1"
LinkTimeCodeGeneration="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
InheritedPropertySheets="..\XBT.vsprops"
UseOfMFC="0"
ATLMinimizesCRunTimeLibraryUsage="false"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
HeaderFileName=""
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="..\misc"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="2"
PrecompiledHeaderThrough="stdafx.h"
WarningLevel="1"
DebugInformationFormat="4"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
PreprocessorDefinitions="_DEBUG"
Culture="1043"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="zlib.lib"
LinkIncremental="2"
IgnoreDefaultLibraryNames="libcmt"
GenerateDebugInformation="true"
SubSystem="1"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<File
RelativePath="..\misc\bt_misc.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="..\misc\bvalue.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="..\misc\bvalue.h"
>
</File>
<File
RelativePath="client.h"
>
</File>
<File
RelativePath="config.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="config.h"
>
</File>
<File
RelativePath="connection.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="connection.h"
>
</File>
<File
RelativePath="..\misc\sql\database.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="epoll.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="epoll.h"
>
</File>
<File
RelativePath="..\misc\windows\nt_service.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="..\misc\windows\nt_service.h"
>
</File>
<File
RelativePath=".\resource.h"
>
</File>
<File
RelativePath="server.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="server.h"
>
</File>
<File
RelativePath="..\misc\sha1.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="..\misc\sha1.h"
>
</File>
<File
RelativePath="..\misc\socket.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="..\misc\sql\sql_query.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="..\misc\sql\sql_result.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="stats.h"
>
</File>
<File
RelativePath="StdAfx.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
UsePrecompiledHeader="1"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
UsePrecompiledHeader="1"
/>
</FileConfiguration>
</File>
<File
RelativePath="StdAfx.h"
>
</File>
<File
RelativePath="..\misc\stream_int.h"
>
</File>
<File
RelativePath="tcp_listen_socket.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="tcp_listen_socket.h"
>
</File>
<File
RelativePath="tracker_input.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="tracker_input.h"
>
</File>
<File
RelativePath="transaction.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="transaction.h"
>
</File>
<File
RelativePath="udp_listen_socket.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="udp_listen_socket.h"
>
</File>
<File
RelativePath="..\misc\virtual_binary.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="XBT Tracker.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath=".\res\XBT Tracker.ico"
>
</File>
<File
RelativePath=".\XBT Tracker.rc"
>
</File>
<File
RelativePath="..\misc\xcc_z.cpp"
>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories=""
PreprocessorDefinitions=""
/>
</FileConfiguration>
</File>
<File
RelativePath="..\misc\xcc_z.h"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View file

@ -1,265 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{73C570AC-E7C3-451D-A5C6-7A2532F0121B}</ProjectGuid>
<RootNamespace>XBT Tracker</RootNamespace>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseOfMfc>false</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\XBT.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\XBT.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkIncremental>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(SolutionDir)$(Configuration)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)\</IntDir>
<LinkIncremental Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</LinkIncremental>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Midl>
<HeaderFileName>
</HeaderFileName>
</Midl>
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<InlineFunctionExpansion>OnlyExplicitInline</InlineFunctionExpansion>
<WholeProgramOptimization>true</WholeProgramOptimization>
<AdditionalIncludeDirectories>..\misc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<StringPooling>true</StringPooling>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<FunctionLevelLinking>true</FunctionLevelLinking>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>stdafx.h</PrecompiledHeaderFile>
<WarningLevel>Level3</WarningLevel>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0413</Culture>
</ResourceCompile>
<Link>
<AdditionalDependencies>zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Console</SubSystem>
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Midl>
<HeaderFileName>
</HeaderFileName>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\misc;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>stdafx.h</PrecompiledHeaderFile>
<WarningLevel>Level1</WarningLevel>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<Culture>0x0413</Culture>
</ResourceCompile>
<Link>
<AdditionalDependencies>zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>libcmt;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<DataExecutionPrevention>
</DataExecutionPrevention>
<TargetMachine>MachineX86</TargetMachine>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\misc\bt_misc.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="..\misc\bvalue.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="config.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="connection.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="..\misc\sql\database.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="epoll.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="..\misc\windows\nt_service.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="server.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="..\misc\sha1.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="..\misc\socket.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="..\misc\sql\sql_query.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="..\misc\sql\sql_result.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="StdAfx.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="tcp_listen_socket.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="tracker_input.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="transaction.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="udp_listen_socket.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="..\misc\virtual_binary.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="XBT Tracker.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
<ClCompile Include="..\misc\xcc_z.cpp">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\misc\bvalue.h" />
<ClInclude Include="client.h" />
<ClInclude Include="config.h" />
<ClInclude Include="connection.h" />
<ClInclude Include="epoll.h" />
<ClInclude Include="..\misc\windows\nt_service.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="server.h" />
<ClInclude Include="..\misc\sha1.h" />
<ClInclude Include="stats.h" />
<ClInclude Include="StdAfx.h" />
<ClInclude Include="..\misc\stream_int.h" />
<ClInclude Include="tcp_listen_socket.h" />
<ClInclude Include="tracker_input.h" />
<ClInclude Include="transaction.h" />
<ClInclude Include="udp_listen_socket.h" />
<ClInclude Include="..\misc\xcc_z.h" />
</ItemGroup>
<ItemGroup>
<None Include="res\XBT Tracker.ico" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="XBT Tracker.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View file

@ -1,27 +0,0 @@
#pragma once
#include <socket.h>
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;
};

View file

@ -1,146 +0,0 @@
#include "stdafx.h"
#include "config.h"
#include <find_ptr.h>
#include <socket.h>
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<bool> 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<int> 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<std::string> 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<std::string>* 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<int>* i = find_ptr(m_attributes_int, name))
*i->value = value;
// TorrentPier // listen_port
else
return set(name, static_cast<bool>(value));
return 0;
}
int Cconfig::set(const std::string& name, bool value)
{
if (t_attribute<bool>* i = find_ptr(m_attributes_bool, name))
*i->value = value;
else
return 1;
return 0;
}

View file

@ -1,75 +0,0 @@
#pragma once
#include <config_base.h>
class Cconfig: public Cconfig_base
{
public:
// TorrentPier begin
typedef std::set<std::string> t_listen_ipas;
typedef std::set<std::string> 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*);
};

View file

@ -1,340 +0,0 @@
#include "stdafx.h"
#include "connection.h"
#include <bt_misc.h>
#include <bt_strings.h>
#include <bvalue.h>
#include <iostream>
#include <xcc_z.h>
#include "server.h"
// TorrentPier begin
#ifdef WIN32
#include <Ws2tcpip.h>
#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<const char*>(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<sockaddr*>(&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<sockaddr_in*>(&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<sockaddr_in6*>(&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<iovec, 2> d;
d[0].iov_base = const_cast<char*>(h.data());
d[0].iov_len = h.size();
d[1].iov_base = const_cast<unsigned char*>(s.data());
d[1].iov_len = s.size();
msghdr m;
m.msg_name = NULL;
m.msg_namelen = 0;
m.msg_iov = const_cast<iovec*>(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;
}

View file

@ -1,33 +0,0 @@
#pragma once
#include "client.h"
#include <vector>
#include <xbt/virtual_binary.h>
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<char, 4 << 10> m_read_b;
Cvirtual_binary m_write_b;
const_memory_range m_r;
memory_range m_w;
};

View file

@ -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
}

View file

@ -1,39 +0,0 @@
#pragma once
#include <boost/utility.hpp>
#ifdef EPOLL
#include <sys/epoll.h>
#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;
};

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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 <stdio.h>
#include <cstring>
// 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();
}

View file

@ -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 <string>
#include <iostream>
// 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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.2 KiB

View file

@ -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

File diff suppressed because it is too large Load diff

View file

@ -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 <boost/ptr_container/ptr_list.hpp>
#include <boost/ptr_container/ptr_map.hpp>
#include <find_ptr.h>
#include <map>
#include <sql/database.h>
#include <xbt/virtual_binary.h>
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<char, 20> 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<char, 16> ipv6;
char ipv6[16];
int host_;
// TorrentPier end
};
typedef std::map<peer_key_c, t_peer> 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<Cconnection> t_connections;
typedef std::list<Ctcp_listen_socket> t_tcp_sockets;
typedef std::list<Cudp_listen_socket> t_udp_sockets;
typedef std::map<std::string, t_file> t_files;
typedef std::map<unsigned int, t_deny_from_host> t_deny_from_hosts;
typedef std::map<int, t_user> t_users;
typedef std::map<std::string, t_user*> 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
};

View file

@ -1,50 +0,0 @@
#pragma once
#include <ctime>
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
};

View file

@ -1 +0,0 @@
#include "stdafx.h"

View file

@ -1,36 +0,0 @@
#pragma once
#include <boost/foreach.hpp>
#include <cassert>
#include <ctime>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <vector>
#ifdef WIN32
#define FD_SETSIZE 1024
#define NOMINMAX
#define atoll _atoi64
#else
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <cstdio>
#include <errno.h>
#include <signal.h>
#include <unistd.h>
// TorrentPier begin
#include <netdb.h>
// TorrentPier end
#endif
typedef unsigned char byte;

View file

@ -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);
}

View file

@ -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&);
};

View file

@ -1,350 +0,0 @@
#include "stdafx.h"
#include "tracker_input.h"
#include <bt_misc.h>
#include <socket.h>
#include <boost/algorithm/string.hpp>
// 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;
}

View file

@ -1,50 +0,0 @@
#pragma once
#include <string>
// TorrentPier begin
#include <socket.h>
// 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<std::string> 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
};

View file

@ -1,164 +0,0 @@
#include "stdafx.h"
#include "transaction.h"
#include <bt_misc.h>
#include <bt_strings.h>
#include <iostream>
#include <sha1.h>
#include <stream_int.h>
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<sockaddr*>(&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<Ctracker_input::t_event>(read_int(4, r + utia_event, r.end));
ti.m_info_hash.assign(reinterpret_cast<const char*>(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<const char*>(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<const sockaddr*>(&m_a), sizeof(sockaddr_in)) != b.size())
std::cerr << "send failed: " << Csocket::error2a(WSAGetLastError()) << std::endl;
}

View file

@ -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;
};

View file

@ -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();
}

View file

@ -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&);
};

View file

@ -1 +0,0 @@
43033

View file

@ -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"

View file

@ -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);
}

View file

@ -1,75 +0,0 @@
#pragma once
#include <ctime>
#include <list>
#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<Calert>
{
public:
void push_back(const value_type& v)
{
std::list<value_type>::push_back(v);
while (size() > 250)
erase(begin());
}
};

View file

@ -1,354 +0,0 @@
#include "stdafx.h"
#include "bt_misc.h"
#include <boost/foreach.hpp>
#include <sys/stat.h>
#include <algorithm>
#include <cstdio>
#include <ctime>
#include <socket.h>
#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<int>((v & 0x3ff) * 100 >> 10);
v >>= 10;
w += sprintf(w, "%d", static_cast<int>(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<int>(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);
}

View file

@ -1,96 +0,0 @@
#pragma once
#include <sha1.h>
#include <string>
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<const unsigned char*>(&v);
long long b = a[0] << 24 | a[1] << 16 | a[2] << 8 | a[3];
return b << 32 | static_cast<long long>(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,
};

View file

@ -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";

View file

@ -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;
}

View file

@ -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<std::string> t_announces;
typedef std::vector<Cfile> 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;
};

View file

@ -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));
}
}

View file

@ -1,39 +0,0 @@
#pragma once
#include <stream_writer.h>
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<Cbt_tracker_account>
{
public:
Cvirtual_binary dump() const;
const Cbt_tracker_account* find(const std::string&) const;
void load(const Cvirtual_binary&);
};

View file

@ -1,82 +0,0 @@
#include "stdafx.h"
#include "bt_tracker_url.h"
#include <boost/algorithm/string.hpp>
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;
}

View file

@ -1,25 +0,0 @@
#pragma once
#include <string>
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;
};

View file

@ -1,370 +0,0 @@
#include "stdafx.h"
#include "bvalue.h"
#include <boost/foreach.hpp>
#include <string.h>
#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<const char*>(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<char*>(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;
}

View file

@ -1,58 +0,0 @@
#pragma once
#include <map>
#include <string>
#include <vector>
#include <xbt/virtual_binary.h>
class Cbvalue
{
public:
enum t_value_type
{
vt_int,
vt_string,
vt_list,
vt_dictionary,
};
typedef std::map<std::string, Cbvalue> t_map;
typedef std::vector<Cbvalue> 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);
};

View file

@ -1,108 +0,0 @@
#pragma once
#include <boost/algorithm/string.hpp>
#include <fstream>
#include <map>
#include <set>
#include <string>
class Cconfig_base
{
public:
template <class T>
struct t_attribute
{
const char* key;
T* value;
T default_value;
};
template <class T>
class t_attributes: public std::map<std::string, t_attribute<T> >
{
};
virtual int set(const std::string& name, const std::string& value)
{
t_attributes<std::string>::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<int>::iterator i = m_attributes_int.find(name);
if (i != m_attributes_int.end())
*i->second.value = value;
else
return set(name, static_cast<bool>(value));
return 0;
}
virtual int set(const std::string& name, bool value)
{
t_attributes<bool>::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<bool> m_attributes_bool;
t_attributes<int> m_attributes_int;
t_attributes<std::string> m_attributes_string;
template <class T>
void fill_map(t_attribute<T>* attributes, const t_attributes<T>* s, t_attributes<T>& d)
{
for (t_attribute<T>* i = attributes; i->key; i++)
{
*i->value = s ? *s->find(i->key)->second.value : i->default_value;
d[i->key] = *i;
}
}
template <class T>
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;
}
}
};

View file

@ -1,252 +0,0 @@
#pragma once
#include <boost/array.hpp>
#include <string>
#include <vector>
template <class T>
class memory_range_base
{
public:
memory_range_base()
{
begin = NULL;
end = NULL;
}
template<class U>
memory_range_base(const memory_range_base<U>& 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<size_t U>
memory_range_base(boost::array<char, U>& v)
{
assign(&v.front(), v.size());
}
template<size_t U>
memory_range_base(boost::array<unsigned char, U>& v)
{
assign(&v.front(), v.size());
}
memory_range_base(std::vector<char>& v)
{
assign(&v.front(), v.size());
}
memory_range_base(std::vector<unsigned char>& v)
{
assign(&v.front(), v.size());
}
memory_range_base assign(void* begin_, void* end_)
{
begin = reinterpret_cast<T>(begin_);
end = reinterpret_cast<T>(end_);
return *this;
}
memory_range_base assign(void* begin_, size_t size)
{
begin = reinterpret_cast<T>(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<const char*>(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<unsigned char*> memory_range;
template <class T>
class const_memory_range_base
{
public:
const_memory_range_base()
{
begin = NULL;
end = NULL;
}
template<class U>
const_memory_range_base(const const_memory_range_base<U>& v)
{
assign(v.begin, v.end);
}
template<class U>
const_memory_range_base(const memory_range_base<U>& 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<size_t U>
const_memory_range_base(const boost::array<char, U>& v)
{
assign(&v.front(), v.size());
}
template<size_t U>
const_memory_range_base(const boost::array<unsigned char, U>& v)
{
assign(&v.front(), v.size());
}
const_memory_range_base(const std::vector<char>& v)
{
assign(&v.front(), v.size());
}
const_memory_range_base(const std::vector<unsigned char>& v)
{
assign(&v.front(), v.size());
}
const_memory_range_base assign(const void* begin_, const void* end_)
{
begin = reinterpret_cast<T>(begin_);
end = reinterpret_cast<T>(end_);
return *this;
}
const_memory_range_base assign(const void* begin_, size_t size)
{
begin = reinterpret_cast<T>(begin_);
end = begin + size;
return *this;
}
void clear()
{
begin = end = NULL;
}
bool empty() const
{
return begin == end;
}
template<class U>
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<const char*>(begin));
}
size_t size() const
{
return end - begin;
}
std::string string() const
{
return std::string(reinterpret_cast<const char*>(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 unsigned char*> const_memory_range;

View file

@ -1,15 +0,0 @@
#pragma once
template <class T, class U>
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 <class T, class U>
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;
}

View file

@ -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 <stdint.h> (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<const uint8_t *>(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<unsigned char*>(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());
}

View file

@ -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 <const_memory_range.h>
#include <string>
#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

View file

@ -1,223 +0,0 @@
#include "stdafx.h"
#include "socket.h"
#ifdef WIN32
#pragma comment(lib, "ws2_32.lib")
#else
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <netdb.h>
#include <unistd.h>
#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<sockaddr*>(&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<sockaddr*>(&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<sockaddr*>(&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<char*>(d.begin), d.size(), MSG_NOSIGNAL);
}
int Csocket::recvfrom(memory_range d, sockaddr* a, socklen_t* cb_a) const
{
return ::recvfrom(*this, reinterpret_cast<char*>(d.begin), d.size(), MSG_NOSIGNAL, a, cb_a);
}
int Csocket::send(const_memory_range s) const
{
return ::send(*this, reinterpret_cast<const char*>(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<const char*>(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<char*>(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<const char*>(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<int*>(*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;
}

View file

@ -1,135 +0,0 @@
#pragma once
#include <boost/intrusive_ptr.hpp>
#include <boost/utility.hpp>
#include <const_memory_range.h>
#include <string>
#ifdef WIN32
#include <winsock2.h>
typedef int socklen_t;
#else
#include <arpa/inet.h>
#include <netinet/in.h>
#include <errno.h>
#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<SOCKET>(*m_source) : INVALID_SOCKET;
}
private:
boost::intrusive_ptr<Csocket_source> m_source;
};

View file

@ -1,71 +0,0 @@
#include "stdafx.h"
#include "database.h"
#include <fstream>
#include <iostream>
#include <stdexcept>
#ifdef WIN32
#pragma comment(lib, "libmysql")
#else
#include <syslog.h>
#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;
}

View file

@ -1,33 +0,0 @@
#pragma once
#include <stdexcept>
#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;
};

View file

@ -1,77 +0,0 @@
#include "stdafx.h"
#include "sql_query.h"
#include <cstdio>
#include <vector>
#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<char> 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<char> r(2 * v.size() + 2);
r.resize(mysql_real_escape_string(m_database.handle(), &r.front() + 1, reinterpret_cast<const char*>(v.begin), v.size()) + 2);
r.front() = '\'';
r.back() = '\'';
p_raw(r);
return *this;
}

View file

@ -1,24 +0,0 @@
#pragma once
#include <const_memory_range.h>
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;
};

View file

@ -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<Csql_result_source>& 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);
}

View file

@ -1,142 +0,0 @@
#pragma once
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/utility.hpp>
#include <const_memory_range.h>
#ifdef _MSC_VER
#include <winsock2.h>
#include <mysql.h>
#else
#include <mysql/mysql.h>
#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_result_source>&);
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<Csql_result_source> m_source;
};
class Csql_result
{
public:
Csql_row fetch_row() const;
Csql_result(MYSQL_RES* h)
{
m_source = boost::make_shared<Csql_result_source>(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<Csql_result_source> m_source;
};

View file

@ -1,83 +0,0 @@
#pragma once
#include <const_memory_range.h>
#include <string.h>
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 <class T>
static T write_float(T w0, float v)
{
unsigned char* w = reinterpret_cast<unsigned char*>(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<const unsigned char*>(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 <class T>
T write_int(int cb, T w0, long long v)
{
unsigned char* w = reinterpret_cast<unsigned char*>(w0);
w += cb;
for (int i = 0; i < cb; i++)
{
*--w = v & 0xff;
v >>= 8;
}
return reinterpret_cast<T>(w + cb);
}
inline long long read_int_le(int cb, const void* r0)
{
const unsigned char* r = reinterpret_cast<const unsigned char*>(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 <class T>
T write_int_le(int cb, T w0, long long v)
{
unsigned char* w = reinterpret_cast<unsigned char*>(w0);
for (int i = 0; i < cb; i++)
{
*w++ = v & 0xff;
v >>= 8;
}
return reinterpret_cast<T>(w);
}

View file

@ -1,3 +0,0 @@
#include "stdafx.h"
#include "stream_reader.h"

View file

@ -1,59 +0,0 @@
#pragma once
#include <stream_int.h>
#include <xbt/virtual_binary.h>
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<const char*>(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;
};

View file

@ -1,2 +0,0 @@
#include "stdafx.h"
#include "stream_writer.h"

View file

@ -1,41 +0,0 @@
#pragma once
#include <const_memory_range.h>
#include <stream_int.h>
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;
};

View file

@ -1,170 +0,0 @@
#include "stdafx.h"
#include "tf_misc.h"
#include <boost/algorithm/string.hpp>
#include <boost/format.hpp>
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 += "&quot;";
break;
case '<':
d += "&lt;";
break;
case '&':
d += "&amp;";
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("<a href=\"%s\">%s</a>") % 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 += "&lt;";
break;
case '&':
r += "&amp;";
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, "> ") ? "<span class=quote>" + line + "</span>" : line;
r += "<br>";
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;
}

View file

@ -1,8 +0,0 @@
#pragma once
#include <string>
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&);

View file

@ -1,75 +0,0 @@
#include "stdafx.h"
#include "xbt/virtual_binary.h"
#include <sys/stat.h>
#include <cstdio>
#include <string.h>
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<Cvirtual_binary_source>(const_memory_range(NULL, v));
}
Cvirtual_binary::Cvirtual_binary(const_memory_range d)
{
m_source = boost::make_shared<Cvirtual_binary_source>(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<Cvirtual_binary_source>(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());
}

File diff suppressed because it is too large Load diff

View file

@ -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 <tr@et-soft.de>
//
// 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 <afxtempl.h>
// 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<int,int>& sizePrimary,
CArray<int,int>& sizeMin, CArray<int,int>& sizeMax);
bool resizeToRelative(int& availSpace, CArray<int,int>& sizePrimary,
CArray<int,int>& sizeMin, CArray<int,int>& sizeMax);
bool resizeToGreedy( int& availSpace, int nGreedy, CArray<int,int>& sizePrimary,
CArray<int,int>& sizeMin, CArray<int,int>& 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<CPaneBase, CPaneBase> 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_)

View file

@ -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<LPARAM>(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;
}

View file

@ -1,3 +0,0 @@
#pragma once
int browse_for_directory(HWND, const std::string& title, std::string& directory);

View file

@ -1,67 +0,0 @@
#include "stdafx.h"
#include "nt_service.h"
#include <windows.h>
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;
}

View file

@ -1,4 +0,0 @@
#pragma once
int nt_service_install(const char* name);
int nt_service_uninstall(const char* name);

View file

@ -1,129 +0,0 @@
#pragma once
#include <boost/make_shared.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/utility.hpp>
#include <cassert>
#include <const_memory_range.h>
#include <string>
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<Cvirtual_binary_source>(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<Cvirtual_binary_source> m_source;
};

View file

@ -1,70 +0,0 @@
#include "stdafx.h"
#include "xcc_z.h"
#include <cstdio>
#include <string.h>
#include <zlib.h>
#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<unsigned char*>(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<unsigned char*>(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<unsigned char*>(s.begin), s.size());
gzflush(f, Z_FINISH);
}

View file

@ -1,10 +0,0 @@
#pragma once
#include <xbt/virtual_binary.h>
namespace xcc_z
{
Cvirtual_binary gunzip(const_memory_range);
Cvirtual_binary gzip(const_memory_range);
void gzip_out(const_memory_range);
}

View file

@ -1,196 +0,0 @@
#include "stdafx.h"
#include "xif_key.h"
#include <zlib.h>
#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<const t_xif_header_fast*>(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<t_xif_header_fast*>(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<t_xif_header_fast*>(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;
}

View file

@ -1,252 +0,0 @@
#pragma once
#include <map>
#include <string>
#include <xbt/virtual_binary.h>
#include <xif_value.h>
const static int file_id = 0x1a464958; // *reinterpret_cast<const int*>("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<int, Cxif_key> t_xif_key_map;
typedef std::map<int, Cxif_value> 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<const long long*>(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;
};

View file

@ -1,86 +0,0 @@
#include "stdafx.h"
#include "xif_key_r.h"
#include <stream_int.h>
#include <xbt/virtual_binary.h>
#include <xif_key.h>
#include <zlib.h>
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<const t_xif_header_fast*>(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;
}

View file

@ -1,97 +0,0 @@
#pragma once
#include <vector>
#include "xif_value.h"
class Cxif_key_r
{
public:
typedef std::vector<std::pair<int, Cxif_key_r> > t_key_map;
typedef std::vector<std::pair<int, Cxif_value> > 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<const long long*>(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;
};

View file

@ -1,151 +0,0 @@
#include "stdafx.h"
#include "xif_value.h"
#include <zlib.h>
#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<t_vt>(*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<t_vt>(*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();
}

View file

@ -1,113 +0,0 @@
#pragma once
#include <string.h>
#include <xbt/virtual_binary.h>
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<const char*>(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;
};
};

Binary file not shown.

View file

@ -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;}

View file

@ -1,6 +0,0 @@
<?php
$mysql_host = 'localhost';
$mysql_user = 'user';
$mysql_pass = 'user';
$mysql_db = 'forum';

View file

@ -1,59 +0,0 @@
<?php
require_once('xbt_config.php');
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<link rel=stylesheet href="xbt.css">
<title>XBT Files</title>
<?php
mysql_connect($mysql_host, $mysql_user, $mysql_pass);
mysql_select_db($mysql_db);
$results = mysql_query("select sum(completed) completed, sum(leechers) leechers, sum(seeders) seeders, sum(leechers or seeders) torrents from xbt_files");
$result = mysql_fetch_assoc($results);
$result['peers'] = $result['leechers'] + $result['seeders'];
echo('<table>');
printf('<tr><th align=right>completed<td align=right>%d<td>', $result['completed']);
printf('<tr><th align=right>peers<td align=right>%d<td align=right>100 %%', $result['peers']);
if ($result['peers'])
{
printf('<tr><th align=right>leechers<td align=right>%d<td align=right>%d %%', $result['leechers'], $result['leechers'] * 100 / $result['peers']);
printf('<tr><th align=right>seeders<td align=right>%d<td align=right>%d %%', $result['seeders'], $result['seeders'] * 100 / $result['peers']);
}
printf('<tr><th align=right>torrents<td align=right>%d<td>', $result['torrents']);
printf('<tr><th align=right>time<td align=right colspan=2>%s', gmdate('Y-m-d H:i:s'));
echo('</table>');
echo('<hr>');
$results = mysql_query("select * from xbt_files where leechers or seeders order by ctime desc");
echo('<table>');
echo('<tr>');
echo('<th>fid');
echo('<th>info_hash');
echo('<th>leechers');
echo('<th>seeders');
echo('<th>completed');
echo('<th>modified');
echo('<th>created');
while ($result = mysql_fetch_assoc($results))
{
echo('<tr>');
printf('<td align=right>%d', $result['fid']);
printf('<td>%s', bin2hex($result['info_hash']));
echo('<td align=right>');
if ($result['leechers'])
printf('%d', $result['leechers']);
echo('<td align=right>');
if ($result['seeders'])
printf('%d', $result['seeders']);
echo('<td align=right>');
if ($result['completed'])
printf('%d', $result['completed']);
printf('<td>%s', gmdate('Y-m-d H:i:s', $result['mtime']));
printf('<td>%s', gmdate('Y-m-d H:i:s', $result['ctime']));
}
echo('</table>');
?>
<hr>
<div>
<a href="http://sourceforge.net/projects/xbtt/"><img src="http://sourceforge.net/sflogo.php?group_id=94951;type=1" alt="XBT project at SF"></a>
<a href="http://w3.org/"><img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!"></a>
<a href="http://w3.org/"><img src="http://w3.org/Icons/valid-html401" alt="Valid HTML 4.01!"></a>
</div>

Binary file not shown.

View file

@ -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)<bt.u_down_total*0.3 then 0 else 1 end
column_users_torrents_limit = case when bt.u_up_total>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

Binary file not shown.

View file

@ -1,2 +0,0 @@
Открыть окно командной строки (Пуск - Выполнить - cmd).
Выполнить C:\путь до файла\"XBT Tracker".exe --install

View file

@ -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)<bt.u_down_total*0.3 then 0 else 1 end
column_users_torrents_limit = case when bt.u_up_total>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

View file

@ -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 = '<td class="tCenter med"><b>'. $compl_perc .'%</b></td>';

View file

@ -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']) ? '&nbsp;<b><sup>&reg;</sup></b>' : '';

View file

@ -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) .")";

View file

@ -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);

Some files were not shown because too many files have changed in this diff Show more