Initial checkin.
authorDavid Bartley <dtbartle@csclub.uwaterloo.ca>
Fri, 13 Jul 2007 05:02:50 +0000 (01:02 -0400)
committerDavid Bartley <dtbartle@csclub.uwaterloo.ca>
Fri, 13 Jul 2007 05:02:50 +0000 (01:02 -0400)
67 files changed:
BNBT.rc [new file with mode: 0644]
BNBT.sln [new file with mode: 0644]
BNBT.vcproj [new file with mode: 0644]
Makefile [new file with mode: 0644]
Makefile.debug [new file with mode: 0644]
atom.cpp [new file with mode: 0644]
atom.h [new file with mode: 0644]
base64.cpp [new file with mode: 0644]
base64.h [new file with mode: 0644]
bencode.cpp [new file with mode: 0644]
bencode.h [new file with mode: 0644]
bnbt-init-script [new file with mode: 0755]
bnbt.cfg [new file with mode: 0644]
bnbt.cpp [new file with mode: 0644]
bnbt.h [new file with mode: 0644]
bnbt_mysql.cpp [new file with mode: 0644]
bnbt_mysql.h [new file with mode: 0644]
client.cpp [new file with mode: 0644]
client.h [new file with mode: 0644]
config.cpp [new file with mode: 0644]
config.h [new file with mode: 0644]
debian/README [new file with mode: 0644]
debian/README.Debian [new file with mode: 0644]
debian/changelog [new file with mode: 0644]
debian/compat [new file with mode: 0644]
debian/control [new file with mode: 0644]
debian/copyright [new file with mode: 0644]
debian/dirs [new file with mode: 0644]
debian/docs [new file with mode: 0644]
debian/init.d [new file with mode: 0644]
debian/postinst [new file with mode: 0644]
debian/postrm [new file with mode: 0644]
debian/rules [new file with mode: 0755]
footer.html [new file with mode: 0644]
header.html [new file with mode: 0644]
icon_done.ico [new file with mode: 0644]
lesser.txt [new file with mode: 0644]
link.cpp [new file with mode: 0644]
link.h [new file with mode: 0644]
md5.cpp [new file with mode: 0644]
md5.h [new file with mode: 0644]
resource.h [new file with mode: 0644]
server.cpp [new file with mode: 0644]
server.h [new file with mode: 0644]
sha1.cpp [new file with mode: 0644]
sha1.h [new file with mode: 0644]
sort.cpp [new file with mode: 0644]
sort.h [new file with mode: 0644]
tracker.cpp [new file with mode: 0644]
tracker.h [new file with mode: 0644]
tracker_admin.cpp [new file with mode: 0644]
tracker_announce.cpp [new file with mode: 0644]
tracker_comments.cpp [new file with mode: 0644]
tracker_file.cpp [new file with mode: 0644]
tracker_index.cpp [new file with mode: 0644]
tracker_info.cpp [new file with mode: 0644]
tracker_login.cpp [new file with mode: 0644]
tracker_scrape.cpp [new file with mode: 0644]
tracker_signup.cpp [new file with mode: 0644]
tracker_stats.cpp [new file with mode: 0644]
tracker_torrent.cpp [new file with mode: 0644]
tracker_upload.cpp [new file with mode: 0644]
tracker_users.cpp [new file with mode: 0644]
util.cpp [new file with mode: 0644]
util.h [new file with mode: 0644]
util_ntservice.cpp [new file with mode: 0644]
util_ntservice.h [new file with mode: 0644]

diff --git a/BNBT.rc b/BNBT.rc
new file mode 100644 (file)
index 0000000..26025f4
--- /dev/null
+++ b/BNBT.rc
@@ -0,0 +1,111 @@
+// Microsoft Visual C++ generated resource script.\r
+//\r
+#include "resource.h"\r
+\r
+#define APSTUDIO_READONLY_SYMBOLS\r
+/////////////////////////////////////////////////////////////////////////////\r
+//\r
+// Generated from the TEXTINCLUDE 2 resource.\r
+//\r
+#include "afxres.h"\r
+\r
+/////////////////////////////////////////////////////////////////////////////\r
+#undef APSTUDIO_READONLY_SYMBOLS\r
+\r
+/////////////////////////////////////////////////////////////////////////////\r
+// English (U.S.) resources\r
+\r
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)\r
+#ifdef _WIN32\r
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US\r
+#pragma code_page(1252)\r
+#endif //_WIN32\r
+\r
+#ifdef APSTUDIO_INVOKED\r
+/////////////////////////////////////////////////////////////////////////////\r
+//\r
+// TEXTINCLUDE\r
+//\r
+\r
+1 TEXTINCLUDE \r
+BEGIN\r
+    "resource.h\0"\r
+END\r
+\r
+2 TEXTINCLUDE \r
+BEGIN\r
+    "#include ""afxres.h""\r\n"\r
+    "\0"\r
+END\r
+\r
+3 TEXTINCLUDE \r
+BEGIN\r
+    "\r\n"\r
+    "\0"\r
+END\r
+\r
+#endif    // APSTUDIO_INVOKED\r
+\r
+\r
+/////////////////////////////////////////////////////////////////////////////\r
+//\r
+// Icon\r
+//\r
+\r
+// Icon with lowest ID value placed first to ensure application icon\r
+// remains consistent on all systems.\r
+IDI_ICON1               ICON                    "icon_done.ico"\r
+\r
+/////////////////////////////////////////////////////////////////////////////\r
+//\r
+// Version\r
+//\r
+\r
+VS_VERSION_INFO VERSIONINFO\r
+ FILEVERSION 8,0,10,0\r
+ PRODUCTVERSION 8,0,10,0\r
+ FILEFLAGSMASK 0x37L\r
+#ifdef _DEBUG\r
+ FILEFLAGS 0x21L\r
+#else\r
+ FILEFLAGS 0x20L\r
+#endif\r
+ FILEOS 0x4L\r
+ FILETYPE 0x1L\r
+ FILESUBTYPE 0x0L\r
+BEGIN\r
+    BLOCK "StringFileInfo"\r
+    BEGIN\r
+        BLOCK "040904b0"\r
+        BEGIN\r
+            VALUE "FileDescription", "CBTT C++ BitTorrent Trakcer - Based on BNBT"\r
+            VALUE "FileVersion", "8, 0, 10, 0"\r
+            VALUE "InternalName", "CBTT"\r
+            VALUE "LegalCopyright", "Copyright (C) 2003 Trevor Hogan, Portions (C) 2004 Harold Feit"\r
+            VALUE "OriginalFilename", "BNBT.EXE"\r
+            VALUE "ProductName", "CBTT C++ BitTorrent Tracker - Based on BNBT"\r
+            VALUE "ProductVersion", "8, 0, 10, 0"\r
+            VALUE "SpecialBuild", "Additional Features enabled - check http://cbtt.depthstrike.com for details."\r
+        END\r
+    END\r
+    BLOCK "VarFileInfo"\r
+    BEGIN\r
+        VALUE "Translation", 0x409, 1200\r
+    END\r
+END\r
+\r
+#endif    // English (U.S.) resources\r
+/////////////////////////////////////////////////////////////////////////////\r
+\r
+\r
+\r
+#ifndef APSTUDIO_INVOKED\r
+/////////////////////////////////////////////////////////////////////////////\r
+//\r
+// Generated from the TEXTINCLUDE 3 resource.\r
+//\r
+\r
+\r
+/////////////////////////////////////////////////////////////////////////////\r
+#endif    // not APSTUDIO_INVOKED\r
+\r
diff --git a/BNBT.sln b/BNBT.sln
new file mode 100644 (file)
index 0000000..a656c1b
--- /dev/null
+++ b/BNBT.sln
@@ -0,0 +1,27 @@
+Microsoft Visual Studio Solution File, Format Version 8.00\r
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BNBT", "BNBT.vcproj", "{35D3F730-C089-412C-96E9-19EE4BC1D6B6}"\r
+       ProjectSection(ProjectDependencies) = postProject\r
+       EndProjectSection\r
+EndProject\r
+Global\r
+       GlobalSection(SolutionConfiguration) = preSolution\r
+               Debug = Debug\r
+               Debug MySQL = Debug MySQL\r
+               Release = Release\r
+               Release MySQL = Release MySQL\r
+       EndGlobalSection\r
+       GlobalSection(ProjectConfiguration) = postSolution\r
+               {35D3F730-C089-412C-96E9-19EE4BC1D6B6}.Debug.ActiveCfg = Debug|Win32\r
+               {35D3F730-C089-412C-96E9-19EE4BC1D6B6}.Debug.Build.0 = Debug|Win32\r
+               {35D3F730-C089-412C-96E9-19EE4BC1D6B6}.Debug MySQL.ActiveCfg = Debug MySQL|Win32\r
+               {35D3F730-C089-412C-96E9-19EE4BC1D6B6}.Debug MySQL.Build.0 = Debug MySQL|Win32\r
+               {35D3F730-C089-412C-96E9-19EE4BC1D6B6}.Release.ActiveCfg = Release|Win32\r
+               {35D3F730-C089-412C-96E9-19EE4BC1D6B6}.Release.Build.0 = Release|Win32\r
+               {35D3F730-C089-412C-96E9-19EE4BC1D6B6}.Release MySQL.ActiveCfg = Release MySQL|Win32\r
+               {35D3F730-C089-412C-96E9-19EE4BC1D6B6}.Release MySQL.Build.0 = Release MySQL|Win32\r
+       EndGlobalSection\r
+       GlobalSection(ExtensibilityGlobals) = postSolution\r
+       EndGlobalSection\r
+       GlobalSection(ExtensibilityAddIns) = postSolution\r
+       EndGlobalSection\r
+EndGlobal\r
diff --git a/BNBT.vcproj b/BNBT.vcproj
new file mode 100644 (file)
index 0000000..8f58a65
--- /dev/null
@@ -0,0 +1,1168 @@
+<?xml version="1.0" encoding="Windows-1252"?>\r
+<VisualStudioProject\r
+       ProjectType="Visual C++"\r
+       Version="7.10"\r
+       Name="BNBT"\r
+       SccProjectName=""\r
+       SccLocalPath="">\r
+       <Platforms>\r
+               <Platform\r
+                       Name="Win32"/>\r
+       </Platforms>\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       OutputDirectory=".\Debug"\r
+                       IntermediateDirectory=".\Debug"\r
+                       ConfigurationType="1"\r
+                       UseOfMFC="0"\r
+                       ATLMinimizesCRunTimeLibraryUsage="FALSE"\r
+                       CharacterSet="2">\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="1"\r
+                               RuntimeTypeInfo="TRUE"\r
+                               UsePrecompiledHeader="2"\r
+                               PrecompiledHeaderFile=".\Debug/BNBT.pch"\r
+                               AssemblerListingLocation=".\Debug/"\r
+                               ObjectFile=".\Debug/"\r
+                               ProgramDataBaseFileName=".\Debug/"\r
+                               WarningLevel="3"\r
+                               SuppressStartupBanner="TRUE"\r
+                               DebugInformationFormat="4"/>\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"/>\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               AdditionalDependencies="wsock32.lib zdll.lib"\r
+                               OutputFile="BNBT.exe"\r
+                               LinkIncremental="0"\r
+                               SuppressStartupBanner="TRUE"\r
+                               IgnoreDefaultLibraryNames="libcd"\r
+                               GenerateDebugInformation="TRUE"\r
+                               ProgramDatabaseFile=".\Debug/BNBT.pdb"\r
+                               SubSystem="1"\r
+                               TargetMachine="1"/>\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                               TypeLibraryName=".\Debug/BNBT.tlb"\r
+                               HeaderFileName=""/>\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"/>\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                               PreprocessorDefinitions="_DEBUG"\r
+                               Culture="1033"/>\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"/>\r
+                       <Tool\r
+                               Name="VCManagedWrapperGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCAuxiliaryManagedWrapperGeneratorTool"/>\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       OutputDirectory=".\Release"\r
+                       IntermediateDirectory=".\Release"\r
+                       ConfigurationType="1"\r
+                       UseOfMFC="0"\r
+                       ATLMinimizesCRunTimeLibraryUsage="FALSE"\r
+                       CharacterSet="2">\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="2"\r
+                               InlineFunctionExpansion="1"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"\r
+                               StringPooling="TRUE"\r
+                               RuntimeLibrary="0"\r
+                               EnableFunctionLevelLinking="TRUE"\r
+                               RuntimeTypeInfo="TRUE"\r
+                               UsePrecompiledHeader="2"\r
+                               PrecompiledHeaderFile=".\Release/BNBT.pch"\r
+                               AssemblerListingLocation=".\Release/"\r
+                               ObjectFile=".\Release/"\r
+                               ProgramDataBaseFileName=".\Release/"\r
+                               WarningLevel="3"\r
+                               SuppressStartupBanner="TRUE"\r
+                               DebugInformationFormat="2"/>\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"/>\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               AdditionalDependencies="ws2_32.lib zdll.lib"\r
+                               OutputFile="BNBT.exe"\r
+                               LinkIncremental="1"\r
+                               SuppressStartupBanner="TRUE"\r
+                               IgnoreDefaultLibraryNames="libc"\r
+                               GenerateDebugInformation="TRUE"\r
+                               ProgramDatabaseFile=".\Release/BNBT.pdb"\r
+                               SubSystem="1"\r
+                               TargetMachine="1"/>\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                               TypeLibraryName=".\Release/BNBT.tlb"\r
+                               HeaderFileName=""/>\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"/>\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                               PreprocessorDefinitions="NDEBUG"\r
+                               Culture="1033"/>\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"/>\r
+                       <Tool\r
+                               Name="VCManagedWrapperGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCAuxiliaryManagedWrapperGeneratorTool"/>\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Debug MySQL|Win32"\r
+                       OutputDirectory="$(ConfigurationName)"\r
+                       IntermediateDirectory="$(ConfigurationName)"\r
+                       ConfigurationType="1"\r
+                       UseOfMFC="0"\r
+                       ATLMinimizesCRunTimeLibraryUsage="FALSE"\r
+                       CharacterSet="2">\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;BNBT_MYSQL"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="1"\r
+                               RuntimeTypeInfo="TRUE"\r
+                               UsePrecompiledHeader="2"\r
+                               PrecompiledHeaderFile=".\Debug MySQL/BNBT.pch"\r
+                               AssemblerListingLocation=".\Debug MySQL/"\r
+                               ObjectFile=".\Debug MySQL/"\r
+                               ProgramDataBaseFileName=".\Debug MySQL/"\r
+                               WarningLevel="3"\r
+                               SuppressStartupBanner="TRUE"\r
+                               DebugInformationFormat="4"/>\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"/>\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               AdditionalDependencies="wsock32.lib zdll.lib libmySQL.lib"\r
+                               OutputFile="BNBTMySQL.exe"\r
+                               LinkIncremental="0"\r
+                               SuppressStartupBanner="TRUE"\r
+                               IgnoreDefaultLibraryNames="libcd"\r
+                               GenerateDebugInformation="TRUE"\r
+                               ProgramDatabaseFile=".\Debug/BNBT.pdb"\r
+                               SubSystem="1"\r
+                               TargetMachine="1"/>\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                               TypeLibraryName=".\Debug/BNBT.tlb"\r
+                               HeaderFileName=""/>\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"/>\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                               PreprocessorDefinitions="_DEBUG"\r
+                               Culture="1033"/>\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"/>\r
+                       <Tool\r
+                               Name="VCManagedWrapperGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCAuxiliaryManagedWrapperGeneratorTool"/>\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release MySQL|Win32"\r
+                       OutputDirectory="$(ConfigurationName)"\r
+                       IntermediateDirectory="$(ConfigurationName)"\r
+                       ConfigurationType="1"\r
+                       UseOfMFC="0"\r
+                       ATLMinimizesCRunTimeLibraryUsage="FALSE"\r
+                       CharacterSet="2">\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="2"\r
+                               InlineFunctionExpansion="1"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;BNBT_MYSQL"\r
+                               StringPooling="TRUE"\r
+                               RuntimeLibrary="0"\r
+                               EnableFunctionLevelLinking="TRUE"\r
+                               RuntimeTypeInfo="TRUE"\r
+                               UsePrecompiledHeader="2"\r
+                               PrecompiledHeaderFile=".\Release MySQL/BNBT.pch"\r
+                               AssemblerListingLocation=".\Release MySQL/"\r
+                               ObjectFile=".\Release MySQL/"\r
+                               ProgramDataBaseFileName=".\Release MySQL/"\r
+                               WarningLevel="3"\r
+                               SuppressStartupBanner="TRUE"\r
+                               DebugInformationFormat="2"/>\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"/>\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               AdditionalDependencies="wsock32.lib zdll.lib libmySQL.lib"\r
+                               OutputFile="BNBTMySQL.exe"\r
+                               LinkIncremental="1"\r
+                               SuppressStartupBanner="TRUE"\r
+                               IgnoreDefaultLibraryNames="libc"\r
+                               GenerateDebugInformation="TRUE"\r
+                               ProgramDatabaseFile=".\Release/BNBT.pdb"\r
+                               SubSystem="1"\r
+                               TargetMachine="1"/>\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                               TypeLibraryName=".\Release/BNBT.tlb"\r
+                               HeaderFileName=""/>\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"/>\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"/>\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                               PreprocessorDefinitions="NDEBUG"\r
+                               Culture="1033"/>\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"/>\r
+                       <Tool\r
+                               Name="VCManagedWrapperGeneratorTool"/>\r
+                       <Tool\r
+                               Name="VCAuxiliaryManagedWrapperGeneratorTool"/>\r
+               </Configuration>\r
+       </Configurations>\r
+       <References>\r
+       </References>\r
+       <Files>\r
+               <Filter\r
+                       Name="Source Files"\r
+                       Filter="cpp;c;cxx;rc;def;r;odl;idl;hpj;bat">\r
+                       <File\r
+                               RelativePath="atom.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\base64.cpp">\r
+                       </File>\r
+                       <File\r
+                               RelativePath="bencode.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath="bnbt.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\bnbt_mysql.cpp">\r
+                       </File>\r
+                       <File\r
+                               RelativePath="client.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath="config.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\link.cpp">\r
+                       </File>\r
+                       <File\r
+                               RelativePath="md5.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath="server.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath="sha1.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\sort.cpp">\r
+                       </File>\r
+                       <File\r
+                               RelativePath="tracker.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath="tracker_admin.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath="tracker_announce.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath="tracker_comments.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath="tracker_file.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath="tracker_index.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath="tracker_info.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath="tracker_login.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath="tracker_scrape.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath="tracker_signup.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath="tracker_stats.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath="tracker_torrent.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath="tracker_upload.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath="tracker_users.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath="util.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+                       <File\r
+                               RelativePath="util_ntservice.cpp">\r
+                               <FileConfiguration\r
+                                       Name="Debug|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Debug MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="0"\r
+                                               PreprocessorDefinitions=""\r
+                                               BasicRuntimeChecks="3"/>\r
+                               </FileConfiguration>\r
+                               <FileConfiguration\r
+                                       Name="Release MySQL|Win32">\r
+                                       <Tool\r
+                                               Name="VCCLCompilerTool"\r
+                                               Optimization="2"\r
+                                               PreprocessorDefinitions=""/>\r
+                               </FileConfiguration>\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Header Files"\r
+                       Filter="h;hpp;hxx;hm;inl">\r
+                       <File\r
+                               RelativePath="atom.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\base64.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath="bencode.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath="bnbt.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\bnbt_mysql.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath="client.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath="config.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\link.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath="md5.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\resource.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath="server.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath="sha1.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\sort.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath="tracker.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath="util.h">\r
+                       </File>\r
+                       <File\r
+                               RelativePath="util_ntservice.h">\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Resource Files"\r
+                       Filter="ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe">\r
+                       <File\r
+                               RelativePath=".\BNBT.rc">\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\icon_done.ico">\r
+                       </File>\r
+               </Filter>\r
+               <File\r
+                       RelativePath=".\Makefile">\r
+                       <FileConfiguration\r
+                               Name="Debug|Win32"\r
+                               ExcludedFromBuild="TRUE">\r
+                               <Tool\r
+                                       Name="VCCustomBuildTool"/>\r
+                       </FileConfiguration>\r
+                       <FileConfiguration\r
+                               Name="Release|Win32"\r
+                               ExcludedFromBuild="TRUE">\r
+                               <Tool\r
+                                       Name="VCCustomBuildTool"/>\r
+                       </FileConfiguration>\r
+                       <FileConfiguration\r
+                               Name="Debug MySQL|Win32"\r
+                               ExcludedFromBuild="TRUE">\r
+                               <Tool\r
+                                       Name="VCCustomBuildTool"/>\r
+                       </FileConfiguration>\r
+                       <FileConfiguration\r
+                               Name="Release MySQL|Win32"\r
+                               ExcludedFromBuild="TRUE">\r
+                               <Tool\r
+                                       Name="VCCustomBuildTool"/>\r
+                       </FileConfiguration>\r
+               </File>\r
+               <File\r
+                       RelativePath=".\Makefile.debug">\r
+               </File>\r
+       </Files>\r
+       <Globals>\r
+       </Globals>\r
+</VisualStudioProject>\r
diff --git a/Makefile b/Makefile
new file mode 100644 (file)
index 0000000..d13aaf8
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,102 @@
+SHELL = /bin/sh
+SYSTEM = $(shell uname)
+C++ = g++
+DFLAGS =
+OFLAGS = -O2 -w
+LFLAGS = -L. -lz
+CFLAGS =
+
+ifeq ($(SYSTEM),Linux) 
+DFLAGS += -D__LINUX__ 
+endif 
+ifeq ($(SYSTEM),Darwin)
+DFLAGS += -D__APPLE__
+OFLAGS += -flat_namespace
+LFLAGS += -lpthread
+else
+LFLAGS += -pthread
+CFLAGS += -pthread
+endif
+
+ifeq ($(SYSTEM),FreeBSD)
+DFLAGS += -D__FREEBSD__
+LFLAGS = -L. -lz -lpthread
+CFLAGS = 
+endif
+
+ifeq ($(SYSTEM),SunOS)
+DFLAGS += -D__SOLARIS__
+LFLAGS = -lresolv -lsocket -lnsl -lpthread
+CFLAGS =
+endif
+
+CFLAGS += $(OFLAGS) $(DFLAGS) -I.
+
+OBJS = atom.o base64.o bencode.o client.o config.o link.o md5.o server.o sha1.o sort.o tracker_admin.o tracker_comments.o tracker_file.o tracker_index.o tracker_info.o tracker_login.o tracker_signup.o tracker_stats.o tracker_torrent.o tracker_upload.o tracker_users.o util.o
+OBJS_BNBT = bnbt.o tracker.o tracker_announce.o tracker_scrape.o
+OBJS_BNBTMYSQL = bnbt.mysql.o bnbt_mysql.mysql.o tracker.mysql.o tracker_announce.mysql.o tracker_scrape.mysql.o
+
+#PROGS = ./bnbt ./bnbtmysql
+PROGS = ./bnbt
+
+all: $(PROGS)
+
+./bnbt: $(OBJS) $(OBJS_BNBT)
+       $(C++) -o ./bnbt $(OBJS) $(OBJS_BNBT) $(LFLAGS)
+
+./bnbtmysql: $(OBJS) $(OBJS_BNBTMYSQL)
+       $(C++) -o ./bnbtmysql $(OBJS) $(OBJS_BNBTMYSQL) $(LFLAGS) -L/usr/lib/mysql -lmysqlclient
+
+clean:
+       rm -f $(OBJS) $(OBJS_BNBT) $(OBJS_BNBTMYSQL) $(PROGS)
+
+%.o: %.cpp
+       $(C++) -o $@ $(CFLAGS) -c $<
+
+%.mysql.o: %.cpp
+       $(C++) -o $@ $(CFLAGS) -DBNBT_MYSQL -c $<
+
+./bnbt: $(OBJS) $(OBJS_BNBT)
+
+./bnbtmysql: $(OBJS) $(OBJS_BNBTMYSQL)
+
+all: $(PROGS)
+
+atom.o: bnbt.h atom.h util.h
+base64.o: base64.h
+bencode.o: bnbt.h atom.h bencode.h util.h
+bnbt.o: bnbt.h config.h link.h server.h util.h
+client.o: bnbt.h atom.h base64.h client.h md5.h server.h tracker.h util.h
+config.o: bnbt.h atom.h config.h tracker.h util.h
+link.o: bnbt.h atom.h bencode.h config.h link.h md5.h server.h tracker.h util.h
+md5.o: md5.h
+server.o: bnbt.h client.h config.h server.h tracker.h util.h
+sha1.o: sha1.h
+sort.o: bnbt.h sort.h tracker.h util.h
+tracker.o: bnbt.h atom.h bencode.h config.h md5.h server.h sort.h tracker.h util.h
+tracker_admin.o: bnbt.h atom.h link.h tracker.h server.h util.h
+tracker_announce.o: bnbt.h atom.h bencode.h link.h tracker.h util.h
+tracker_comments.o: bnbt.h atom.h tracker.h util.h
+tracker_file.o: bnbt.h atom.h tracker.h util.h
+tracker_index.o: bnbt.h atom.h sort.h tracker.h util.h
+tracker_info.o: bnbt.h atom.h bencode.h tracker.h util.h
+tracker_login.o: bnbt.h atom.h tracker.h util.h
+tracker_scrape.o: bnbt.h atom.h bencode.h tracker.h util.h
+tracker_signup.o: bnbt.h atom.h tracker.h util.h
+tracker_stats.o: bnbt.h atom.h bencode.h sort.h tracker.h util.h
+tracker_torrent.o: bnbt.h atom.h bencode.h tracker.h util.h
+tracker_upload.o: bnbt.h atom.h bencode.h client.h tracker.h util.h
+tracker_users.o: bnbt.h atom.h md5.h sort.h tracker.h util.h
+util.o: bnbt.h atom.h bencode.h sha1.h tracker.h util.h
+
+bnbt.mysql.o: bnbt.h bnbt_mysql.h config.h link.h server.h util.h
+bnbt_mysql.mysql.o: bnbt.h bnbt_mysql.h util.h
+tracker.mysql.o: bnbt.h bnbt_mysql.h atom.h bencode.h config.h md5.h server.h sort.h tracker.h util.h
+tracker_announce.mysql.o: bnbt.h bnbt_mysql.h atom.h bencode.h link.h tracker.h util.h
+tracker_scrape.mysql.o: bnbt.h bnbt_mysql.h atom.h bencode.h tracker.h util.h
+
+install: $(PROGS)
+       install -m 755 bnbt $(DESTDIR)/usr/bin
+#      install -m 755 bnbtmysql $(DESTDIR)/bin
+       install -m 644 bnbt.cfg $(DESTDIR)/etc/bnbt.cfg
diff --git a/Makefile.debug b/Makefile.debug
new file mode 100644 (file)
index 0000000..e53689f
--- /dev/null
@@ -0,0 +1,96 @@
+SHELL = /bin/sh\r
+SYSTEM = $(shell uname)\r
+C++ = g++\r
+DFLAGS =\r
+OFLAGS = -w\r
+LFLAGS = -L. -lz\r
+CFLAGS =\r
+\r
+ifeq ($(SYSTEM),Linux) \r
+DFLAGS += -D__LINUX__ \r
+endif \r
+\r
+ifeq ($(SYSTEM),Darwin)\r
+DFLAGS += -D__APPLE__\r
+OFLAGS += -flat_namespace\r
+LFLAGS += -lpthread\r
+else\r
+LFLAGS += -pthread\r
+CFLAGS += -pthread\r
+endif\r
+\r
+ifeq ($(SYSTEM),FreeBSD)\r
+DFLAGS += -D__FREEBSD__\r
+LFLAGS = -L. -lz -lpthread\r
+CFLAGS = \r
+endif\r
+\r
+ifeq ($(SYSTEM),SunOS)\r
+DFLAGS += -D__SOLARIS__\r
+LFLAGS = -lresolv -lsocket -lnsl -lpthread\r
+CFLAGS =\r
+endif\r
+\r
+CFLAGS += $(OFLAGS) $(DFLAGS) -I.\r
+\r
+OBJS = atom.o base64.o bencode.o client.o config.o link.o md5.o server.o sha1.o sort.o tracker_admin.o tracker_comments.o tracker_file.o tracker_index.o tracker_info.o tracker_login.o tracker_signup.o tracker_stats.o tracker_torrent.o tracker_upload.o tracker_users.o util.o\r
+OBJS_BNBT = bnbt.o tracker.o tracker_announce.o tracker_scrape.o\r
+OBJS_BNBTMYSQL = bnbt.mysql.o bnbt_mysql.mysql.o tracker.mysql.o tracker_announce.mysql.o tracker_scrape.mysql.o\r
+\r
+PROGS = ./bnbt ./bnbtmysql\r
+\r
+all: $(OBJS) $(OBJS_BNBT) $(OBJS_BNBTMYSQL) $(PROGS)\r
+\r
+./bnbt: $(OBJS) $(OBJS_BNBT)\r
+       $(C++) -g -o ./bnbt $(OBJS) $(OBJS_BNBT) $(LFLAGS)\r
+\r
+./bnbtmysql: $(OBJS) $(OBJS_BNBTMYSQL)\r
+       $(C++) -g -o ./bnbtmysql $(OBJS) $(OBJS_BNBTMYSQL) $(LFLAGS) -L/usr/lib/mysql -lmysqlclient\r
+\r
+clean:\r
+       rm -f $(OBJS) $(OBJS_BNBT) $(OBJS_BNBTMYSQL) $(PROGS)\r
+\r
+%.o: %.cpp\r
+       $(C++) -g -o $@ $(CFLAGS) -c $<\r
+\r
+%.mysql.o: %.cpp\r
+       $(C++) -g -o $@ $(CFLAGS) -DBNBT_MYSQL -c $<\r
+\r
+./bnbt: $(OBJS) $(OBJS_BNBT)\r
+\r
+./bnbtmysql: $(OBJS) $(OBJS_BNBTMYSQL)\r
+\r
+all: $(PROGS)\r
+\r
+atom.o: bnbt.h atom.h util.h\r
+base64.o: base64.h\r
+bencode.o: bnbt.h atom.h bencode.h util.h\r
+bnbt.o: bnbt.h config.h link.h server.h util.h\r
+client.o: bnbt.h atom.h base64.h client.h md5.h server.h tracker.h util.h\r
+config.o: bnbt.h atom.h config.h tracker.h util.h\r
+link.o: bnbt.h atom.h bencode.h config.h link.h md5.h server.h tracker.h util.h\r
+md5.o: md5.h\r
+server.o: bnbt.h client.h config.h server.h tracker.h util.h\r
+sha1.o: sha1.h\r
+sort.o: bnbt.h sort.h tracker.h util.h\r
+tracker.o: bnbt.h atom.h bencode.h config.h md5.h server.h sort.h tracker.h util.h\r
+tracker_admin.o: bnbt.h atom.h link.h tracker.h server.h util.h\r
+tracker_announce.o: bnbt.h atom.h bencode.h link.h tracker.h util.h\r
+tracker_comments.o: bnbt.h atom.h tracker.h util.h\r
+tracker_file.o: bnbt.h atom.h tracker.h util.h\r
+tracker_index.o: bnbt.h atom.h sort.h tracker.h util.h\r
+tracker_info.o: bnbt.h atom.h bencode.h tracker.h util.h\r
+tracker_login.o: bnbt.h atom.h tracker.h util.h\r
+tracker_scrape.o: bnbt.h atom.h bencode.h tracker.h util.h\r
+tracker_signup.o: bnbt.h atom.h tracker.h util.h\r
+tracker_stats.o: bnbt.h atom.h bencode.h sort.h tracker.h util.h\r
+tracker_torrent.o: bnbt.h atom.h bencode.h tracker.h util.h\r
+tracker_upload.o: bnbt.h atom.h bencode.h client.h tracker.h util.h\r
+tracker_users.o: bnbt.h atom.h md5.h sort.h tracker.h util.h\r
+util.o: bnbt.h atom.h bencode.h sha1.h tracker.h util.h\r
+\r
+bnbt.mysql.o: bnbt.h bnbt_mysql.h config.h link.h server.h util.h\r
+bnbt_mysql.mysql.o: bnbt.h bnbt_mysql.h util.h\r
+tracker.mysql.o: bnbt.h bnbt_mysql.h atom.h bencode.h config.h md5.h server.h sort.h tracker.h util.h\r
+tracker_announce.mysql.o: bnbt.h bnbt_mysql.h atom.h bencode.h link.h tracker.h util.h\r
+tracker_scrape.mysql.o: bnbt.h bnbt_mysql.h atom.h bencode.h tracker.h util.h
\ No newline at end of file
diff --git a/atom.cpp b/atom.cpp
new file mode 100644 (file)
index 0000000..adcab91
--- /dev/null
+++ b/atom.cpp
@@ -0,0 +1,441 @@
+/***\r
+*\r
+* BNBT Beta 8.0 - A C++ BitTorrent Tracker\r
+* Copyright (C) 2003-2004 Trevor Hogan\r
+*\r
+* CBTT variations (C) 2003-2005 Harold Feit\r
+*\r
+* This library is free software; you can redistribute it and/or\r
+* modify it under the terms of the GNU Lesser General Public\r
+* License as published by the Free Software Foundation; either\r
+* version 2.1 of the License, or (at your option) any later version.\r
+*\r
+* This library is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+* Lesser General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU Lesser General Public\r
+* License along with this library; if not, write to the Free Software\r
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+*\r
+***/\r
+\r
+#include "bnbt.h"\r
+#include "atom.h"\r
+#include "util.h"\r
+\r
+//\r
+// CAtomInt\r
+//\r
+\r
+CAtomInt :: CAtomInt( )\r
+{\r
+       setValue( 0 );\r
+}\r
+\r
+CAtomInt :: CAtomInt( int iInt )\r
+{\r
+       setValue( iInt );\r
+}\r
+\r
+CAtomInt :: CAtomInt( const CAtomInt &c )\r
+{\r
+       // copy constructor\r
+\r
+       setValue( c.getValue( ) );\r
+}\r
+\r
+CAtomInt :: ~CAtomInt( )\r
+{\r
+\r
+}\r
+\r
+int CAtomInt :: EncodedLength( )\r
+{\r
+       return toString( ).size( ) + 2;\r
+}\r
+\r
+int CAtomInt :: Length( )\r
+{\r
+       return toString( ).size( );\r
+}\r
+\r
+string CAtomInt :: toString( )\r
+{\r
+       char pBuf[32];\r
+       memset( pBuf, 0, sizeof( char ) * 32 );\r
+       sprintf( pBuf, "%d", getValue( ) );\r
+       return pBuf;\r
+}\r
+\r
+int CAtomInt :: getValue( ) const\r
+{\r
+       return m_iInt;\r
+}\r
+\r
+void CAtomInt :: setValue( int iInt )\r
+{\r
+       m_iInt = iInt;\r
+}\r
+\r
+//\r
+// CAtomLong\r
+//\r
+\r
+CAtomLong :: CAtomLong( )\r
+{\r
+       setValue( 0 );\r
+}\r
+\r
+CAtomLong :: CAtomLong( int64 iLong )\r
+{\r
+       setValue( iLong );\r
+}\r
+\r
+CAtomLong :: CAtomLong( const CAtomLong &c )\r
+{\r
+       // copy constructor\r
+\r
+       setValue( c.getValue( ) );\r
+}\r
+\r
+CAtomLong :: ~CAtomLong( )\r
+{\r
+\r
+}\r
+\r
+int CAtomLong :: EncodedLength( )\r
+{\r
+       return toString( ).size( ) + 2;\r
+}\r
+\r
+int CAtomLong :: Length( )\r
+{\r
+       return toString( ).size( );\r
+}\r
+\r
+string CAtomLong :: toString( )\r
+{\r
+       char pBuf[32];\r
+       memset( pBuf, 0, sizeof( char ) * 32 );\r
+\r
+#if defined( WIN32 )\r
+       sprintf( pBuf, "%I64d", getValue( ) );\r
+#elif defined( __FREEBSD__ )\r
+       sprintf( pBuf, "%qd", getValue( ) );\r
+#else\r
+       sprintf( pBuf, "%lld", getValue( ) );\r
+#endif\r
+\r
+       return pBuf;\r
+}\r
+\r
+int64 CAtomLong :: getValue( ) const\r
+{\r
+       return m_iLong;\r
+}\r
+\r
+void CAtomLong :: setValue( int64 iLong )\r
+{\r
+       m_iLong = iLong;\r
+}\r
+\r
+//\r
+// CAtomString\r
+//\r
+\r
+CAtomString :: CAtomString( )\r
+{\r
+\r
+}\r
+\r
+CAtomString :: CAtomString( string strString )\r
+{\r
+       setValue( strString );\r
+}\r
+\r
+CAtomString :: CAtomString( const CAtomString &c )\r
+{\r
+       // copy constructor\r
+\r
+       setValue( c.getValue( ) );\r
+}\r
+\r
+CAtomString :: ~CAtomString( )\r
+{\r
+\r
+}\r
+\r
+int CAtomString :: EncodedLength( )\r
+{\r
+       int iSize = getValue( ).size( );\r
+       char pBuf[32];\r
+       memset( pBuf, 0, sizeof( char ) * 32 );\r
+       sprintf( pBuf, "%d", iSize );\r
+       return iSize + strlen( pBuf ) + 1;\r
+}\r
+\r
+int CAtomString :: Length( )\r
+{\r
+       return getValue( ).size( );\r
+}\r
+\r
+string CAtomString :: toString( )\r
+{\r
+       return getValue( );\r
+}\r
+\r
+string CAtomString :: getValue( ) const\r
+{\r
+       return m_strString;\r
+}\r
+\r
+void CAtomString :: setValue( string strString )\r
+{\r
+       m_strString = strString;\r
+}\r
+\r
+//\r
+// CAtomList\r
+//\r
+\r
+CAtomList :: CAtomList( )\r
+{\r
+\r
+}\r
+\r
+CAtomList :: CAtomList( vector<CAtom *> vecList )\r
+{\r
+       setValue( vecList );\r
+}\r
+\r
+CAtomList :: CAtomList( const CAtomList &c )\r
+{\r
+       // copy constructor\r
+\r
+       vector<CAtom *> *pvecList = c.getValuePtr( );\r
+\r
+       for( vector<CAtom *> :: iterator i = pvecList->begin( ); i != pvecList->end( ); i++ )\r
+       {\r
+               if( dynamic_cast<CAtomInt *>( *i ) )\r
+                       addItem( new CAtomInt( *dynamic_cast<CAtomInt *>( *i ) ) );\r
+               else if( dynamic_cast<CAtomLong *>( *i ) )\r
+                       addItem( new CAtomLong( *dynamic_cast<CAtomLong *>( *i ) ) );\r
+               else if( dynamic_cast<CAtomString *>( *i ) )\r
+                       addItem( new CAtomString( *dynamic_cast<CAtomString *>( *i ) ) );\r
+               else if( dynamic_cast<CAtomList *>( *i ) )\r
+                       addItem( new CAtomList( *dynamic_cast<CAtomList *>( *i ) ) );\r
+               else if( dynamic_cast<CAtomDicti *>( *i ) )\r
+                       addItem( new CAtomDicti( *dynamic_cast<CAtomDicti *>( *i ) ) );\r
+               else\r
+                       UTIL_LogPrint( "error copying list - found invalid atom, ignoring\n" );\r
+       }\r
+}\r
+\r
+CAtomList :: ~CAtomList( )\r
+{\r
+       clear( );\r
+}\r
+\r
+int CAtomList :: EncodedLength( )\r
+{\r
+       int iLen = 0;\r
+\r
+       for( vector<CAtom *> :: iterator i = m_vecList.begin( ); i != m_vecList.end( ); i++ )\r
+               iLen += (*i)->EncodedLength( );\r
+\r
+       return iLen + 2;\r
+}\r
+\r
+int CAtomList :: Length( )\r
+{\r
+       // nobody cares about you\r
+\r
+       return 0;\r
+}\r
+\r
+string CAtomList :: toString( )\r
+{\r
+       return string( );\r
+}\r
+\r
+bool CAtomList :: isEmpty( )\r
+{\r
+       return m_vecList.empty( );\r
+}\r
+\r
+void CAtomList :: clear( )\r
+{\r
+       for( vector<CAtom *> :: iterator i = m_vecList.begin( ); i != m_vecList.end( ); i++ )\r
+               delete *i;\r
+\r
+       m_vecList.clear( );\r
+}\r
+\r
+void CAtomList :: Randomize( )\r
+{\r
+       random_shuffle( m_vecList.begin( ), m_vecList.end( ) );\r
+}\r
+\r
+vector<CAtom *> CAtomList :: getValue( ) const\r
+{\r
+       return m_vecList;\r
+}\r
+\r
+vector<CAtom *> *CAtomList :: getValuePtr( ) const\r
+{\r
+       return (vector<CAtom *> *)&m_vecList;\r
+}\r
+\r
+void CAtomList :: setValue( vector<CAtom *> vecList )\r
+{\r
+       m_vecList = vecList;\r
+}\r
+\r
+void CAtomList :: delItem( CAtom *atmItem )\r
+{\r
+       for( vector<CAtom *> :: iterator i = m_vecList.begin( ); i != m_vecList.end( ); i++ )\r
+       {\r
+               if( *i == atmItem )\r
+               {\r
+                       delete *i;\r
+\r
+                       m_vecList.erase( i );\r
+\r
+                       return;\r
+               }\r
+       }\r
+}\r
+\r
+void CAtomList :: addItem( CAtom *atmItem )\r
+{\r
+       m_vecList.push_back( atmItem );\r
+}\r
+\r
+//\r
+// CAtomDicti\r
+//\r
+\r
+CAtomDicti :: CAtomDicti( )\r
+{\r
+\r
+}\r
+\r
+CAtomDicti :: CAtomDicti( const CAtomDicti &c )\r
+{\r
+       // copy constructor\r
+\r
+       map<string, CAtom *> *pmapDicti = c.getValuePtr( );\r
+\r
+       for( map<string, CAtom *> :: iterator i = pmapDicti->begin( ); i != pmapDicti->end( ); i++ )\r
+       {\r
+               if( dynamic_cast<CAtomInt *>( (*i).second ) )\r
+                       setItem( (*i).first, new CAtomInt( *dynamic_cast<CAtomInt *>( (*i).second ) ) );\r
+               else if( dynamic_cast<CAtomLong *>( (*i).second ) )\r
+                       setItem( (*i).first, new CAtomLong( *dynamic_cast<CAtomLong *>( (*i).second ) ) );\r
+               else if( dynamic_cast<CAtomString *>( (*i).second ) )\r
+                       setItem( (*i).first, new CAtomString( *dynamic_cast<CAtomString *>( (*i).second ) ) );\r
+               else if( dynamic_cast<CAtomList *>( (*i).second ) )\r
+                       setItem( (*i).first, new CAtomList( *dynamic_cast<CAtomList *>( (*i).second ) ) );\r
+               else if( dynamic_cast<CAtomDicti *>( (*i).second ) )\r
+                       setItem( (*i).first, new CAtomDicti( *dynamic_cast<CAtomDicti *>( (*i).second ) ) );\r
+               else\r
+                       UTIL_LogPrint( "error copying dictionary - found invalid atom, ignoring\n" );\r
+       }\r
+}\r
+\r
+CAtomDicti :: ~CAtomDicti( )\r
+{\r
+       clear( );\r
+}\r
+\r
+int CAtomDicti :: EncodedLength( )\r
+{\r
+       int iLen = 0;\r
+\r
+       for( map<string, CAtom *> :: iterator i = m_mapDicti.begin( ); i != m_mapDicti.end( ); i++ )\r
+               iLen += CAtomString( (*i).first ).EncodedLength( ) + (*i).second->EncodedLength( );\r
+\r
+       return iLen + 2;\r
+}\r
+\r
+int CAtomDicti :: Length( )\r
+{\r
+       // nobody cares about you\r
+\r
+       return 0;\r
+}\r
+\r
+string CAtomDicti :: toString( )\r
+{\r
+       return string( );\r
+}\r
+\r
+bool CAtomDicti :: isEmpty( )\r
+{\r
+       return m_mapDicti.empty( );\r
+}\r
+\r
+void CAtomDicti :: clear( )\r
+{\r
+       for( map<string, CAtom *> :: iterator i = m_mapDicti.begin( ); i != m_mapDicti.end( ); i++ )\r
+       {\r
+               // UTIL_LogPrint( "deleting element %s\n", (*i).first.c_str( ) );\r
+\r
+               delete (*i).second;\r
+       }\r
+\r
+       m_mapDicti.clear( );\r
+}\r
+\r
+map<string, CAtom *> *CAtomDicti :: getValuePtr( ) const\r
+{\r
+       return (map<string, CAtom *> *)&m_mapDicti;\r
+}\r
+\r
+void CAtomDicti :: delItem( string strKey )\r
+{\r
+       map<string, CAtom *> :: iterator i = m_mapDicti.find( strKey );\r
+\r
+       if( i != m_mapDicti.end( ) )\r
+       {\r
+               delete (*i).second;\r
+\r
+               m_mapDicti.erase( i );\r
+       }\r
+}\r
+\r
+CAtom *CAtomDicti :: getItem( string strKey )\r
+{\r
+       map<string, CAtom *> :: iterator i = m_mapDicti.find( strKey );\r
+\r
+       if( i == m_mapDicti.end( ) )\r
+               return NULL;\r
+       else\r
+               return (*i).second;\r
+}\r
+\r
+CAtom *CAtomDicti :: getItem( string strKey, CAtom *pReturn )\r
+{\r
+       map<string, CAtom *> :: iterator i = m_mapDicti.find( strKey );\r
+\r
+       if( i == m_mapDicti.end( ) )\r
+               return pReturn;\r
+       else\r
+               return (*i).second;\r
+}\r
+\r
+void CAtomDicti :: setItem( string strKey, CAtom *pValue )\r
+{\r
+       map<string, CAtom *> :: iterator i = m_mapDicti.find( strKey );\r
+\r
+       if( i == m_mapDicti.end( ) )\r
+               m_mapDicti.insert( pair<string, CAtom *>( strKey, pValue ) );\r
+       else\r
+       {\r
+               delete (*i).second;\r
+\r
+               (*i).second = pValue;\r
+       }\r
+}\r
diff --git a/atom.h b/atom.h
new file mode 100644 (file)
index 0000000..15c8c81
--- /dev/null
+++ b/atom.h
@@ -0,0 +1,139 @@
+//\r
+// Copyright (C) 2003-2004 Trevor Hogan\r
+//\r
+\r
+#ifndef ATOM_H\r
+ #define ATOM_H\r
+\r
+class CAtom\r
+{\r
+public:\r
+       virtual ~CAtom( ) { }\r
+\r
+       virtual bool isLong( )          { return false; }\r
+       virtual bool isList( )          { return false; }\r
+       virtual bool isDicti( )         { return false; }\r
+\r
+       virtual int EncodedLength( ) = 0;\r
+       virtual int Length( ) = 0;\r
+       virtual string toString( ) = 0;\r
+};\r
+\r
+class CAtomInt : public CAtom\r
+{\r
+public:\r
+       CAtomInt( );\r
+       CAtomInt( int iInt );\r
+       CAtomInt( const CAtomInt &c );\r
+       virtual ~CAtomInt( );\r
+\r
+       virtual int EncodedLength( );\r
+       virtual int Length( );\r
+       virtual string toString( );\r
+\r
+       int getValue( ) const;\r
+       void setValue( int iInt );\r
+\r
+private:\r
+       int m_iInt;\r
+};\r
+\r
+class CAtomLong : public CAtom\r
+{\r
+public:\r
+       CAtomLong( );\r
+       CAtomLong( int64 iLong );\r
+       CAtomLong( const CAtomLong &c );\r
+       virtual ~CAtomLong( );\r
+\r
+       virtual bool isLong( )          { return true; }\r
+\r
+       virtual int EncodedLength( );\r
+       virtual int Length( );\r
+       virtual string toString( );\r
+\r
+       int64 getValue( ) const;\r
+       void setValue( int64 iLong );\r
+\r
+private:\r
+       int64 m_iLong;\r
+};\r
+\r
+class CAtomString : public CAtom\r
+{\r
+public:\r
+       CAtomString( );\r
+       CAtomString( string strString );\r
+       CAtomString( const CAtomString &c );\r
+       virtual ~CAtomString( );\r
+\r
+       virtual int EncodedLength( );\r
+       virtual int Length( );\r
+       virtual string toString( );\r
+\r
+       string getValue( ) const;\r
+       void setValue( string strString );\r
+\r
+private:\r
+       string m_strString;\r
+};\r
+\r
+class CAtomList : public CAtom\r
+{\r
+public:\r
+       CAtomList( );\r
+       CAtomList( vector<CAtom *> vecList );\r
+       CAtomList( const CAtomList &c );\r
+       virtual ~CAtomList( );\r
+\r
+       virtual bool isList( )          { return true; }\r
+\r
+       virtual int EncodedLength( );\r
+       virtual int Length( );\r
+       virtual string toString( );\r
+\r
+       virtual bool isEmpty( );\r
+       virtual void clear( );\r
+\r
+       virtual void Randomize( );\r
+\r
+       vector<CAtom *> getValue( ) const;\r
+       vector<CAtom *> *getValuePtr( ) const;\r
+       void setValue( vector<CAtom *> vecList );\r
+\r
+       void delItem( CAtom *atmItem );\r
+       void addItem( CAtom *atmItem );\r
+\r
+private:\r
+       vector<CAtom *> m_vecList;\r
+};\r
+\r
+class CAtomDicti : public CAtom\r
+{\r
+public:\r
+       CAtomDicti( );\r
+       CAtomDicti( const CAtomDicti &c );\r
+       virtual ~CAtomDicti( );\r
+\r
+       virtual bool isDicti( )         { return true; }\r
+\r
+       virtual int EncodedLength( );\r
+       virtual int Length( );\r
+       virtual string toString( );\r
+\r
+       virtual bool isEmpty( );\r
+       virtual void clear( );\r
+\r
+       map<string, CAtom *> *getValuePtr( ) const;\r
+       void setValue( map<string, CAtom *> mapDicti );\r
+\r
+       void delItem( string strKey );\r
+       CAtom *getItem( string strKey );\r
+       CAtom *getItem( string strKey, CAtom *pReturn );\r
+       void setItem( string strKey, CAtom *pValue );\r
+\r
+private:\r
+       map<string, CAtom *> m_mapDicti;\r
+};\r
+\r
+#endif\r
diff --git a/base64.cpp b/base64.cpp
new file mode 100644 (file)
index 0000000..a428919
--- /dev/null
@@ -0,0 +1,253 @@
+/*---------------------------------------------------------------------------*/\r
+/* base64                                                                    */\r
+/* ======                                                                    */\r
+/*                                                                           */\r
+/* Base64 is a stand-alone C program to encode 7-Bit ASCII strings into      */\r
+/* base64 encoded strings and decode base64 encoded strings back into 7 bit  */\r
+/* ASCII strings.                                                            */\r
+/*                                                                           */\r
+/* Base64 encoding is sometimes used for simple HTTP authentication. That is */\r
+/* when strong encryption isn't necessary, Base64 encryption is used to      */\r
+/* authenticate User-ID's and Passwords.                                     */\r
+/*                                                                           */\r
+/* Base64 processes a string by octets (3 Byte blocks).  For every octet in  */\r
+/* the decoded string, four byte blocks are generated in the encoded string. */\r
+/* If the decoded string length is not a multiple of 3, the Base64 algorithm */\r
+/* pads the end of the encoded string with equal signs '='.                  */\r
+/*                                                                           */\r
+/* An example taken from RFC 2617 (HTTP Authentication):                     */\r
+/*                                                                           */\r
+/* Resource (URL) requires basic authentication (Authorization: Basic) for   */\r
+/* access, otherwise a HTTP 401 Unauthorized response is returned.           */\r
+/*                                                                           */\r
+/* User-ID:Password string  = "Aladdin:open sesame"                          */\r
+/* Base64 encoded   string  = "QWxhZGRpbjpvcGVuIHNlc2FtZQ=="                 */\r
+/*                                                                           */\r
+/* Usage:   base64 OPTION [STRING]                                           */\r
+/* ------                                                                    */\r
+/* OPTION:  -h Displays a brief messages.                                    */\r
+/*          -e Base64 encode the 7-Bit ASCII STRING.                         */\r
+/*          -d Decode the Base64 STRING to 7-Bit ASCII.                      */\r
+/*                                                                           */\r
+/* STRING:  Either a 7-Bit ASCII text string for encoding or a Base64        */\r
+/*          encoded string for decoding back to 7-Bit ASCII.                 */\r
+/*                                                                           */\r
+/* Note:    For EBCDIC and other collating sequences, the STRING must first  */\r
+/*          be converted to 7-Bit ASCII before passing it to this module and */\r
+/*          the return string must be converted back to the appropriate      */\r
+/*          collating sequence.                                              */\r
+/*                                                                           */\r
+/* Student Exercises:                                                        */\r
+/* ------------------                                                        */\r
+/* 1. Modify base64 to accept an additional parameter "Quiet Mode" (-q) to   */\r
+/*    optionally supress the ending statistics and only display the encoded  */\r
+/*    or decoded string.                                                     */\r
+/*                                                                           */\r
+/* 2. Make base64 callable from another program as follows:                  */\r
+/*    a. Add an externally callable function to determine and return the     */\r
+/*       size of the buffer required for encoding or decoding.               */\r
+/*    b. Make base64 accept three parameters; input and output buffer point- */\r
+/*       ers and a flag for indicate encoding or decoding.                   */\r
+/*    c. Modify base64 so that a calling program can:                        */\r
+/*       i.   Request the size of a buffer required either for encoding or   */\r
+/*            decoding.                                                      */\r
+/*       ii.  Allocate a buffer based on the result from the previous        */\r
+/*            call.                                                          */\r
+/*       iii. Call base64 with the appropriate pointers and flag to encode   */\r
+/*            or decode a string into the callers buffer.                    */\r
+/*                                                                           */\r
+/* Copyright (c) 1994 - 2001                                                 */\r
+/* Marc Niegowski                                                            */\r
+/* Connectivity, Inc.                                                        */\r
+/* All rights reserved.                                                      */\r
+/*---------------------------------------------------------------------------*/\r
+#include    <stdlib.h>                      // calloc and free prototypes.\r
+#include    <stdio.h>                       // printf prototype.\r
+#include    <string.h>                      // str* and memset prototypes.\r
+\r
+#include "base64.h"\r
+\r
+typedef\r
+unsigned\r
+char    uchar;                              // Define unsigned char as uchar.\r
+\r
+typedef\r
+unsigned\r
+int     uint;                               // Define unsigned int as uint.\r
+\r
+char   *b64decode(const char *);            // Decodes a string to ASCII.\r
+bool    b64valid(uchar *);                  // Tests for a valid Base64 char.\r
+char   *b64isnot(char *);                   // Displays an invalid message.\r
+char   *b64buffer(const char *, bool);      // Alloc. encoding/decoding buffer.\r
+\r
+// Macro definitions:\r
+\r
+#define b64is7bit(c)  ((c) > 0x7f ? 0 : 1)  // Valid 7-Bit ASCII character?\r
+#define b64blocks(l) (((l) + 2) / 3 * 4 + 1)// Length rounded to 4 byte block.\r
+#define b64octets(l)  ((l) / 4  * 3 + 1)    // Length rounded to 3 byte octet. \r
+\r
+// Note:    Tables are in hex to support different collating sequences\r
+\r
+static\r
+const                                       // Base64 encoding and decoding\r
+uchar   pBase64[]   =   {                   // table.\r
+                        0x3e, 0x7f, 0x7f, 0x7f, 0x3f, 0x34, 0x35, 0x36,\r
+                        0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x7f,\r
+                        0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x00, 0x01,\r
+                        0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,\r
+                        0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11,\r
+                        0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,\r
+                        0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x1a, 0x1b,\r
+                        0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23,\r
+                        0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b,\r
+                        0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33\r
+                        };\r
+\r
+/*---------------------------------------------------------------------------*/\r
+/* b64decode - Decode a Base64 string to a 7-Bit ASCII string.               */\r
+/* ===========================================================               */\r
+/*                                                                           */\r
+/* Call with:   char *  - The Base64 string to decode.                       */\r
+/*                                                                           */\r
+/* Returns:     bool    - True (!0) if the operation was successful.         */\r
+/*                        False (0) if the operation was unsuccessful.       */\r
+/*---------------------------------------------------------------------------*/\r
+char *b64decode(const char *s)\r
+{\r
+    int     l = strlen(s);                  // Get length of Base64 string.\r
+    char   *b;                              // Decoding buffer pointers.\r
+    uchar   c = 0;                          // Character to decode.\r
+    int     x = 0;                          // General purpose integers.\r
+    int     y = 0;\r
+\r
+    static                                  // Collating sequence...\r
+    const                                   // ...independant "===".\r
+    char    pPad[]  =   {0x3d, 0x3d, 0x3d, 0x00};\r
+\r
+    if  (l % 4)                             // If it's not modulo 4, then it...\r
+        return b64isnot(NULL);              // ...can't be a Base64 string.\r
+\r
+    if  (b = strchr(s, pPad[0]))            // Only one, two or three equal...\r
+    {                                       // ...'=' signs are allowed at...\r
+        if  ((b - s) < (l - 3))             // ...the end of the Base64 string.\r
+            return b64isnot(NULL);          // Any other equal '=' signs are...\r
+        else                                // ...invalid.\r
+            if  (strncmp(b, (char *) pPad + 3 - (s + l - b), s + l - b))\r
+                return b64isnot(NULL);\r
+    }\r
+\r
+    if  (!(b = b64buffer(s, false)))        // Allocate a decoding buffer.\r
+        return NULL;                        // Can't allocate decoding buffer.\r
+\r
+    x = 0;                                  // Initialize index.\r
+\r
+    while ((c = *s++))                      // Decode every byte of the...\r
+    {                                       // Base64 string.\r
+        if  (c == pPad[0])                  // Ignore "=".\r
+            break;\r
+\r
+        if (!b64valid(&c))                  // Valid Base64 Index?\r
+            return b64isnot(b);             // No, return false.\r
+        \r
+        switch(x % 4)                       // Decode 4 byte words into...\r
+        {                                   // ...3 byte octets.\r
+        case    0:                          // Byte 0 of word.\r
+            b[y]    =  c << 2;\r
+            break;                          \r
+        case    1:                          // Byte 1 of word.\r
+            b[y]   |=  c >> 4;\r
+\r
+            if (!b64is7bit((uchar) b[y++])) // Is 1st byte of octet valid?\r
+                return b64isnot(b);         // No, return false.\r
+\r
+            b[y]    = (c & 0x0f) << 4;\r
+            break;\r
+        case    2:                          // Byte 2 of word.\r
+            b[y]   |=  c >> 2;\r
+\r
+            if (!b64is7bit((uchar) b[y++])) // Is 2nd byte of octet valid?\r
+                return b64isnot(b);         // No, return false.\r
+\r
+            b[y]    = (c & 0x03) << 6;\r
+            break;\r
+        case    3:                          // Byte 3 of word.\r
+            b[y]   |=  c;\r
+\r
+            if (!b64is7bit((uchar) b[y++])) // Is 3rd byte of octet valid?\r
+                return b64isnot(b);         // No, return false.\r
+        }\r
+        x++;                                // Increment word byte.\r
+    }\r
+\r
+       return b;\r
+}\r
+\r
+/*---------------------------------------------------------------------------*/\r
+/* b64valid - validate the character to decode.                              */\r
+/* ============================================                              */\r
+/*                                                                           */\r
+/* Checks whether the character to decode falls within the boundaries of the */\r
+/* Base64 decoding table.                                                    */\r
+/*                                                                           */\r
+/* Call with:   char    - The Base64 character to decode.                    */\r
+/*                                                                           */\r
+/* Returns:     bool    - True (!0) if the character is valid.               */\r
+/*                        False (0) if the character is not valid.           */\r
+/*---------------------------------------------------------------------------*/\r
+bool b64valid(uchar *c)\r
+{\r
+    if ((*c < 0x2b) || (*c > 0x7a))         // If not within the range of...\r
+        return false;                       // ...the table, return false.\r
+    \r
+    if ((*c = pBase64[*c - 0x2b]) == 0x7f)  // If it falls within one of...\r
+        return false;                       // ...the gaps, return false.\r
+\r
+    return true;                            // Otherwise, return true.\r
+}\r
+\r
+/*---------------------------------------------------------------------------*/\r
+/* b64isnot - Display an error message and clean up.                         */\r
+/* =================================================                         */\r
+/*                                                                           */\r
+/* Call this routine to display a message indicating that the string being   */\r
+/* decoded is an invalid Base64 string and de-allocate the decoding buffer.  */\r
+/*                                                                           */\r
+/* Call with:   char *  - Pointer to the Base64 string being decoded.        */\r
+/*              char *  - Pointer to the decoding buffer or NULL if it isn't */\r
+/*                        allocated and doesn't need to be de-allocated.     */\r
+/*                                                                           */\r
+/* Returns:     bool    - True (!0) if the character is valid.               */\r
+/*                        False (0) if the character is not valid.           */\r
+/*---------------------------------------------------------------------------*/\r
+char *b64isnot(char *b)\r
+{\r
+    if  (b)                                 // If the buffer pointer is not...\r
+        free(b);                            // ...NULL, de-allocate it.\r
+\r
+    return  NULL;\r
+}\r
+\r
+/*---------------------------------------------------------------------------*/\r
+/* b64buffer - Allocate the decoding or encoding buffer.                     */\r
+/* =====================================================                     */\r
+/*                                                                           */\r
+/* Call this routine to allocate an encoding buffer in 4 byte blocks or a    */\r
+/* decoding buffer in 3 byte octets.  We use "calloc" to initialize the      */\r
+/* buffer to 0x00's for strings.                                             */\r
+/*                                                                           */\r
+/* Call with:   char *  - Pointer to the string to be encoded or decoded.    */\r
+/*              bool    - True (!0) to allocate an encoding buffer.          */\r
+/*                        False (0) to allocate a decoding buffer.           */\r
+/*                                                                           */\r
+/* Returns:     char *  - Pointer to the buffer or NULL if the buffer        */\r
+/*                        could not be allocated.                            */\r
+/*---------------------------------------------------------------------------*/\r
+char *b64buffer(const char *s, bool f)\r
+{\r
+    int     l = strlen(s);                  // String size to encode or decode.\r
+\r
+    if  (!l)                                // If the string size is 0...\r
+        return  NULL;                       // ...return null.\r
+\r
+    return (char *)calloc((f ? b64blocks(l) : b64octets(l)),sizeof(char));\r
+}\r
diff --git a/base64.h b/base64.h
new file mode 100644 (file)
index 0000000..53f9ee3
--- /dev/null
+++ b/base64.h
@@ -0,0 +1,5 @@
+//\r
+// Copyright (C) 2003-2004 Trevor Hogan\r
+//\r
+\r
+extern char *b64decode(const char *);\r
diff --git a/bencode.cpp b/bencode.cpp
new file mode 100644 (file)
index 0000000..e31f031
--- /dev/null
@@ -0,0 +1,339 @@
+/***\r
+*\r
+* BNBT Beta 8.0 - A C++ BitTorrent Tracker\r
+* Copyright (C) 2003-2004 Trevor Hogan\r
+*\r
+* CBTT variations (C) 2003-2005 Harold Feit\r
+*\r
+* This library is free software; you can redistribute it and/or\r
+* modify it under the terms of the GNU Lesser General Public\r
+* License as published by the Free Software Foundation; either\r
+* version 2.1 of the License, or (at your option) any later version.\r
+*\r
+* This library is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+* Lesser General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU Lesser General Public\r
+* License along with this library; if not, write to the Free Software\r
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+*\r
+***/\r
+\r
+#include "bnbt.h"\r
+#include "atom.h"\r
+#include "bencode.h"\r
+#include "util.h"\r
+\r
+string EncodeInt( const CAtomInt &x )\r
+{\r
+       char pBuf[128];\r
+\r
+       memset( pBuf, 0, sizeof( char ) * 128 );\r
+\r
+       sprintf( pBuf, "%d", x.getValue( ) );\r
+\r
+       string strDest;\r
+\r
+       strDest += "i";\r
+       strDest += pBuf;\r
+       strDest += "e";\r
+\r
+       return strDest;\r
+}\r
+\r
+string EncodeLong( const CAtomLong &x )\r
+{\r
+       char pBuf[128];\r
+\r
+       memset( pBuf, 0, sizeof( char ) * 128 );\r
+\r
+#if defined( WIN32 )\r
+       sprintf( pBuf, "%I64d", x.getValue( ) );\r
+#elif defined( __FREEBSD__ )\r
+       sprintf( pBuf, "%qd", x.getValue( ) );\r
+#else\r
+       sprintf( pBuf, "%lld", x.getValue( ) );\r
+#endif\r
+\r
+       string strDest;\r
+\r
+       strDest += "i";\r
+       strDest += pBuf;\r
+       strDest += "e";\r
+\r
+       return strDest;\r
+}\r
+\r
+string EncodeString( const CAtomString &x )\r
+{\r
+       char pBuf[128];\r
+\r
+       memset( pBuf, 0, sizeof( char ) * 128 );\r
+\r
+       sprintf( pBuf, "%u", (unsigned int)x.getValue( ).size( ) );\r
+\r
+       string strDest;\r
+\r
+       strDest += pBuf;\r
+       strDest += ":";\r
+       strDest += x.getValue( );\r
+\r
+       return strDest;\r
+}\r
+\r
+string EncodeList( const CAtomList &x )\r
+{\r
+       vector<CAtom *> *pv = x.getValuePtr( );\r
+\r
+       string strDest;\r
+\r
+       strDest += "l";\r
+\r
+       for( vector<CAtom *> :: iterator i = pv->begin( ); i != pv->end( ); i++ )\r
+       {\r
+               if( dynamic_cast<CAtomInt *>( *i ) )\r
+                       strDest += EncodeInt( *dynamic_cast<CAtomInt *>( *i ) );\r
+               else if( dynamic_cast<CAtomLong *>( *i ) )\r
+                       strDest += EncodeLong( *dynamic_cast<CAtomLong *>( *i ) );\r
+               else if( dynamic_cast<CAtomString *>( *i ) )\r
+                       strDest += EncodeString( *dynamic_cast<CAtomString *>( *i ) );\r
+               else if( dynamic_cast<CAtomList *>( *i ) )\r
+                       strDest += EncodeList( *dynamic_cast<CAtomList *>( *i ) );\r
+               else if( dynamic_cast<CAtomDicti *>( *i ) )\r
+                       strDest += EncodeDicti( *dynamic_cast<CAtomDicti *>( *i ) );\r
+       }\r
+\r
+       strDest += "e";\r
+\r
+       return strDest;\r
+}\r
+\r
+string EncodeDicti( const CAtomDicti &x )\r
+{\r
+       map<string, CAtom *> *pmapDicti = x.getValuePtr( );\r
+\r
+       string strDest;\r
+\r
+       strDest += "d";\r
+\r
+       for( map<string, CAtom *> :: iterator i = pmapDicti->begin( ); i != pmapDicti->end( ); i++ )\r
+       {\r
+               strDest += EncodeString( CAtomString( (*i).first ) );\r
+\r
+               if( dynamic_cast<CAtomInt *>( (*i).second ) )\r
+                       strDest += EncodeInt( *dynamic_cast<CAtomInt *>( (*i).second ) );\r
+               else if( dynamic_cast<CAtomLong *>( (*i).second ) )\r
+                       strDest += EncodeLong( *dynamic_cast<CAtomLong *>( (*i).second ) );\r
+               else if( dynamic_cast<CAtomString *>( (*i).second ) )\r
+                       strDest += EncodeString( *dynamic_cast<CAtomString *>( (*i).second ) );\r
+               else if( dynamic_cast<CAtomList *>( (*i).second ) )\r
+                       strDest += EncodeList( *dynamic_cast<CAtomList *>( (*i).second ) );\r
+               else if( dynamic_cast<CAtomDicti *>( (*i).second ) )\r
+                       strDest += EncodeDicti( *dynamic_cast<CAtomDicti *>( (*i).second ) );\r
+       }\r
+\r
+       strDest += "e";\r
+\r
+       return strDest;\r
+}\r
+\r
+string Encode( CAtom *pAtom )\r
+{\r
+       if( dynamic_cast<CAtomInt *>( pAtom ) )\r
+               return EncodeInt( *dynamic_cast<CAtomInt *>( pAtom ) );\r
+       else if( dynamic_cast<CAtomLong *>( pAtom ) )\r
+               return EncodeLong( *dynamic_cast<CAtomLong *>( pAtom ) );\r
+       else if( dynamic_cast<CAtomString *>( pAtom ) )\r
+               return EncodeString( *dynamic_cast<CAtomString *>( pAtom ) );\r
+       else if( dynamic_cast<CAtomList *>( pAtom ) )\r
+               return EncodeList( *dynamic_cast<CAtomList *>( pAtom ) );\r
+       else if( dynamic_cast<CAtomDicti *>( pAtom ) )\r
+               return EncodeDicti( *dynamic_cast<CAtomDicti *>( pAtom ) );\r
+\r
+       return string( );\r
+}\r
+\r
+/*\r
+\r
+CAtomInt *DecodeInt( const string &x, unsigned long iStart )\r
+{\r
+       string :: size_type iEnd = x.find( "e" );\r
+\r
+       if( iEnd == string :: npos )\r
+       {\r
+               UTIL_LogPrint( "error decoding int - couldn't find \"e\", halting decode\n" );\r
+\r
+               return NULL;\r
+       }\r
+\r
+       return new CAtomInt( atoi( x.substr( iStart + 1, iEnd - iStart - 1 ).c_str( ) ) );\r
+}\r
+\r
+*/\r
+\r
+CAtomLong *DecodeLong( const string &x, unsigned long iStart )\r
+{\r
+       string :: size_type iEnd = x.find( "e", iStart );\r
+\r
+       if( iEnd == string :: npos )\r
+       {\r
+               UTIL_LogPrint( "error decoding long - couldn't find \"e\", halting decode\n" );\r
+\r
+               return NULL;\r
+       }\r
+\r
+       int64 i;\r
+\r
+#if defined( WIN32 )\r
+       sscanf( x.substr( iStart + 1, iEnd - iStart - 1 ).c_str( ), "%I64d", &i );\r
+#elif defined( __FREEBSD__ )\r
+       sscanf( x.substr( iStart + 1, iEnd - iStart - 1 ).c_str( ), "%qd", &i );\r
+#else\r
+       sscanf( x.substr( iStart + 1, iEnd - iStart - 1 ).c_str( ), "%lld", &i );\r
+#endif\r
+\r
+       return new CAtomLong( i );\r
+}\r
+\r
+CAtomString *DecodeString( const string &x, unsigned long iStart )\r
+{\r
+       string :: size_type iSplit = x.find_first_not_of( "1234567890", iStart );\r
+\r
+       if( iSplit == string :: npos )\r
+       {\r
+               UTIL_LogPrint( "error decoding string - couldn't find \":\", halting decode\n" );\r
+\r
+               return NULL;\r
+       }\r
+\r
+       return new CAtomString( x.substr( iSplit + 1, atoi( x.substr( iStart, iSplit - iStart ).c_str( ) ) ) );\r
+}\r
+\r
+CAtomList *DecodeList( const string &x, unsigned long iStart )\r
+{\r
+       unsigned long i = iStart + 1;\r
+\r
+       CAtomList *pList = new CAtomList( );\r
+\r
+       while( i < x.size( ) && x[i] != 'e' )\r
+       {\r
+               CAtom *pAtom = Decode( x, i );\r
+\r
+               if( pAtom )\r
+               {\r
+                       i += pAtom->EncodedLength( );\r
+\r
+                       pList->addItem( pAtom );\r
+               }\r
+               else\r
+               {\r
+                       UTIL_LogPrint( "error decoding list - error decoding list item, discarding list\n" );\r
+\r
+                       delete pList;\r
+\r
+                       return NULL;\r
+               }\r
+       }\r
+\r
+       return pList;\r
+}\r
+\r
+CAtomDicti *DecodeDicti( const string &x, unsigned long iStart )\r
+{\r
+       unsigned long i = iStart + 1;\r
+\r
+       CAtomDicti *pDicti = new CAtomDicti( );\r
+\r
+       while( i < x.size( ) && x[i] != 'e' )\r
+       {\r
+               CAtom *pKey = Decode( x, i );\r
+\r
+               if( pKey && dynamic_cast<CAtomString *>( pKey ) )\r
+               {\r
+                       i += pKey->EncodedLength( );\r
+\r
+                       string strKey = pKey->toString( );\r
+\r
+                       delete pKey;\r
+\r
+                       if( i < x.size( ) )\r
+                       {\r
+                               CAtom *pValue = Decode( x, i );\r
+\r
+                               if( pValue )\r
+                               {\r
+                                       i += pValue->EncodedLength( );\r
+\r
+                                       pDicti->setItem( strKey, pValue );\r
+                               }\r
+                               else\r
+                               {\r
+                                       UTIL_LogPrint( "error decoding dictionary - error decoding value, discarding dictionary\n" );\r
+\r
+                                       delete pDicti;\r
+\r
+                                       return NULL;\r
+                               }\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       UTIL_LogPrint( "error decoding dictionary - error decoding key, discarding dictionary\n" );\r
+\r
+                       delete pDicti;\r
+\r
+                       return NULL;\r
+               }\r
+       }\r
+\r
+       return pDicti;\r
+}\r
+\r
+CAtom *Decode( const string &x, unsigned long iStart )\r
+{\r
+       if( iStart < x.size( ) )\r
+       {\r
+               if( x[iStart] == 'i' )\r
+                       return DecodeLong( x, iStart );\r
+               else if( isdigit( x[iStart] ) )\r
+                       return DecodeString( x, iStart );\r
+               else if( x[iStart] == 'l' )\r
+                       return DecodeList( x, iStart );\r
+               else if( x[iStart] == 'd' )\r
+                       return DecodeDicti( x, iStart );\r
+\r
+               string temp = x.substr( iStart );\r
+\r
+               UTIL_LogPrint( "error decoding - found unexpected character %u, halting decode\n", (unsigned char)x[iStart] );\r
+       }\r
+       else\r
+               UTIL_LogPrint( "error decoding - out of range\n" );\r
+\r
+       return NULL;\r
+}\r
+\r
+CAtom *DecodeFile( const char *szFile )\r
+{\r
+       FILE *pFile = NULL;\r
+\r
+       if( ( pFile = fopen( szFile, "rb" ) ) == NULL )\r
+       {\r
+               UTIL_LogPrint( "warning - unable to open %s for reading\n", szFile );\r
+\r
+               return NULL;\r
+       }\r
+\r
+       fseek( pFile, 0, SEEK_END );\r
+       unsigned long ulFileSize = ftell( pFile );\r
+       fseek( pFile, 0, SEEK_SET );\r
+       char *pData = (char *)malloc( sizeof( char ) * ulFileSize );\r
+       memset( pData, 0, sizeof( char ) * ulFileSize );\r
+       fread( (void *)pData, sizeof( char ), ulFileSize, pFile );\r
+       fclose( pFile );\r
+       string strFile( pData, ulFileSize );\r
+       free( pData );\r
+\r
+       return Decode( strFile );\r
+}\r
diff --git a/bencode.h b/bencode.h
new file mode 100644 (file)
index 0000000..a171840
--- /dev/null
+++ b/bencode.h
@@ -0,0 +1,26 @@
+//\r
+// Copyright (C) 2003-2004 Trevor Hogan\r
+//\r
+\r
+#ifndef BENCODE_H\r
+ #define BENCODE_H\r
+\r
+string EncodeInt( const CAtomInt &x );\r
+string EncodeLong( const CAtomLong &x );\r
+string EncodeString( const CAtomString &x );\r
+string EncodeList( const CAtomList &x );\r
+string EncodeDicti( const CAtomDicti &x );\r
+string Encode( CAtom *pAtom );\r
+\r
+// the decode functions allocate memory, so be SURE to delete it\r
+\r
+// CAtomInt *DecodeInt( const string &x, unsigned long iStart = 0 );\r
+CAtomLong *DecodeLong( const string &x, unsigned long iStart = 0 );\r
+CAtomString *DecodeString( const string &x, unsigned long iStart = 0 );\r
+CAtomList *DecodeList( const string &x, unsigned long iStart = 0 );\r
+CAtomDicti *DecodeDicti( const string &x, unsigned long iStart = 0 );\r
+CAtom *Decode( const string &x, unsigned long iStart = 0 );\r
+\r
+CAtom *DecodeFile( const char *szFile );\r
+\r
+#endif\r
diff --git a/bnbt-init-script b/bnbt-init-script
new file mode 100755 (executable)
index 0000000..2d5d0b7
--- /dev/null
@@ -0,0 +1,155 @@
+#! /bin/sh
+### BEGIN INIT INFO
+# Provides:          skeleton
+# Required-Start:    $local_fs $remote_fs
+# Required-Stop:     $local_fs $remote_fs
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Example initscript
+# Description:       This file should be used to construct scripts to be
+#                    placed in /etc/init.d.
+### END INIT INFO
+
+# Author: Foo Bar <foobar@baz.org>
+#
+# Please remove the "Author" lines above and replace them
+# with your own name if you copy and modify this script.
+
+# Do NOT "set -e"
+
+# PATH should only include /usr/* if it runs after the mountnfs.sh script
+PATH=/sbin:/usr/sbin:/bin:/usr/bin
+DESC="bnbt BitTorrent Tracker"
+NAME=bnbt
+DAEMON=/usr/local/bin/$NAME
+DAEMON_ARGS=""
+PIDFILE=/var/run/$NAME.pid
+SCRIPTNAME=/etc/init.d/$NAME
+
+# Exit if the package is not installed
+[ -x "$DAEMON" ] || exit 0
+
+# Read configuration variable file if it is present
+[ -r /etc/default/$NAME ] && . /etc/default/$NAME
+
+# Load the VERBOSE setting and other rcS variables
+. /lib/init/vars.sh
+
+# Define LSB log_* functions.
+# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
+. /lib/lsb/init-functions
+
+#
+# Function that starts the daemon/service
+#
+do_start()
+{
+       # Return
+       #   0 if daemon has been started
+       #   1 if daemon was already running
+       #   2 if daemon could not be started
+       start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON --test > /dev/null \
+               || return 1
+       start-stop-daemon --start --quiet --pidfile $PIDFILE --exec $DAEMON -- \
+               $DAEMON_ARGS \
+               || return 2
+       # Add code here, if necessary, that waits for the process to be ready
+       # to handle requests from services started subsequently which depend
+       # on this one.  As a last resort, sleep for some time.
+}
+
+#
+# Function that stops the daemon/service
+#
+do_stop()
+{
+       # Return
+       #   0 if daemon has been stopped
+       #   1 if daemon was already stopped
+       #   2 if daemon could not be stopped
+       #   other if a failure occurred
+       start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
+       RETVAL="$?"
+       [ "$RETVAL" = 2 ] && return 2
+       # Wait for children to finish too if this is a daemon that forks
+       # and if the daemon is only ever run from this initscript.
+       # If the above conditions are not satisfied then add some other code
+       # that waits for the process to drop all resources that could be
+       # needed by services started subsequently.  A last resort is to
+       # sleep for some time.
+       start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $DAEMON
+       [ "$?" = 2 ] && return 2
+       # Many daemons don't delete their pidfiles when they exit.
+       rm -f $PIDFILE
+       return "$RETVAL"
+}
+
+#
+# Function that sends a SIGHUP to the daemon/service
+#
+do_reload() {
+       #
+       # If the daemon can reload its configuration without
+       # restarting (for example, when it is sent a SIGHUP),
+       # then implement that here.
+       #
+       start-stop-daemon --stop --signal 1 --quiet --pidfile $PIDFILE --name $NAME
+       return 0
+}
+
+case "$1" in
+  start)
+       [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
+       do_start
+       case "$?" in
+               0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+               2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+       esac
+       ;;
+  stop)
+       [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
+       do_stop
+       case "$?" in
+               0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
+               2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
+       esac
+       ;;
+  #reload|force-reload)
+       #
+       # If do_reload() is not implemented then leave this commented out
+       # and leave 'force-reload' as an alias for 'restart'.
+       #
+       #log_daemon_msg "Reloading $DESC" "$NAME"
+       #do_reload
+       #log_end_msg $?
+       #;;
+  restart|force-reload)
+       #
+       # If the "reload" option is implemented then remove the
+       # 'force-reload' alias
+       #
+       log_daemon_msg "Restarting $DESC" "$NAME"
+       do_stop
+       case "$?" in
+         0|1)
+               do_start
+               case "$?" in
+                       0) log_end_msg 0 ;;
+                       1) log_end_msg 1 ;; # Old process is still running
+                       *) log_end_msg 1 ;; # Failed to start
+               esac
+               ;;
+         *)
+               # Failed to stop
+               log_end_msg 1
+               ;;
+       esac
+       ;;
+  *)
+       #echo "Usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}" >&2
+       echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
+       exit 3
+       ;;
+esac
+
+:
diff --git a/bnbt.cfg b/bnbt.cfg
new file mode 100644 (file)
index 0000000..5309a54
--- /dev/null
+++ b/bnbt.cfg
@@ -0,0 +1,144 @@
+allowed_dir = /var/lib/bnbt/torrents
+announce_interval = 1800
+bind = 129.97.134.12
+bnbt_access_log_dir = 
+bnbt_access_log_file_pattern = %Y-%m-%d.log
+bnbt_allow_comments = 0
+bnbt_allow_info_link = 0
+bnbt_allow_scrape = 1
+bnbt_allow_scrape_global = 0
+bnbt_allow_search = 1
+bnbt_allow_sort = 1
+bnbt_allow_torrent_downloads = 1
+bnbt_archive_dir = 
+bnbt_charset = iso-8859-1
+bnbt_comment_length = 800
+bnbt_comments_file = 
+bnbt_compression_level = 6
+bnbt_count_unique_peers = 1
+bnbt_debug = 0
+bnbt_delete_invalid = 0
+bnbt_delete_own_torrents = 1
+bnbt_disable_html = 0
+bnbt_dump_xml_file = 
+bnbt_dump_xml_interval = 600
+bnbt_dump_xml_peers = 1
+bnbt_error_log_dir = 
+bnbt_error_log_file_pattern = %Y-%m-%de.log
+bnbt_external_torrent_dir = 
+bnbt_file_dir = /var/lib/bnbt/files
+bnbt_file_expires = 180
+bnbt_flush_interval = 100
+bnbt_force_announce_on_download = 0
+bnbt_force_announce_url = 
+bnbt_guest_access = 3
+bnbt_max_conns = 256
+bnbt_max_peers_display = 500
+bnbt_max_recv_size = 524288
+bnbt_max_torrents = 0
+bnbt_member_access = 79
+bnbt_name_length = 32
+bnbt_parse_on_upload = 1
+bnbt_per_page = 1000
+bnbt_private_tracker_flag = 0
+bnbt_realm = BNBT
+bnbt_refresh_fast_cache_interval = 30
+bnbt_refresh_static_interval = 10
+bnbt_require_announce_key = 1
+bnbt_robots_txt = 
+bnbt_rss_channel_copyright = 
+bnbt_rss_channel_description = BitTorrent RSS Feed for BNBT
+bnbt_rss_channel_image_height = 0
+bnbt_rss_channel_image_url = 
+bnbt_rss_channel_image_width = 0
+bnbt_rss_channel_language = en-us
+bnbt_rss_channel_link = http://localhost:26213/
+bnbt_rss_channel_title = My BNBT RSS Feed
+bnbt_rss_channel_ttl = 60
+bnbt_rss_file = 
+bnbt_rss_file_mode = 0
+bnbt_rss_interval = 30
+bnbt_rss_limit = 25
+bnbt_rss_online_dir = 
+bnbt_rss_online_url = 
+bnbt_show_added = 0
+bnbt_show_average_dl_rate = 1
+bnbt_show_average_left = 0
+bnbt_show_average_ul_rate = 1
+bnbt_show_completed = 1
+bnbt_show_file_comment = 0
+bnbt_show_file_contents = 1
+bnbt_show_gen_time = 1
+bnbt_show_info_hash = 0
+bnbt_show_left_as_progress = 1
+bnbt_show_max_left = 0
+bnbt_show_min_left = 0
+bnbt_show_num_files = 0
+bnbt_show_share_ratios = 1
+bnbt_show_size = 1
+bnbt_show_stats = 1
+bnbt_show_transferred = 1
+bnbt_show_uploader = 0
+bnbt_static_footer = 
+bnbt_static_header = 
+bnbt_style_sheet = /files/bluesteel-3.02.css
+bnbt_swap_torrent_link = 0
+bnbt_tag_file = /var/lib/bnbt/tags.bnbt
+bnbt_tlink_bind = 
+bnbt_tlink_connect = 
+bnbt_tlink_password = 
+bnbt_tlink_port = 5204
+bnbt_tlink_server = 0
+bnbt_tracker_title = 
+bnbt_upload_dir = /var/lib/bnbt/torrents
+bnbt_use_announce_key = 1
+bnbt_users_file = /var/lib/bnbt/users.bnbt
+bnbt_users_per_page = 50
+cbtt_abuse_detection = 0
+cbtt_abuse_hammer_limit = 10
+cbtt_abuse_limit = 5
+cbtt_ban_file = /var/lib/bnbt/clientbans.bnbt
+cbtt_ban_mode = 0
+cbtt_blacklist_below_1024 = 0
+cbtt_blacklist_common_p2p_ports = 0
+cbtt_block_private_ip = 0
+cbtt_dont_compress_torrents = 0
+cbtt_download_link_image = 
+cbtt_hide_login_links = 0
+cbtt_ip_ban_mode = 0
+cbtt_ipban_file = /var/lib/bnbt/bans.bnbt
+cbtt_page_number_count = 3
+cbtt_require_compact = 0
+cbtt_require_no_peer_id = 0
+cbtt_restrict_overflow = 0
+cbtt_restrict_overflow_limit = 1099511627776
+cbtt_restricted_peer_spoofing = 0
+cbtt_scrape_file = 
+cbtt_scrape_save_interval = 0
+cbtt_service_name = BNBT Service
+cbtt_stats_link_image = 
+dfile = /var/lib/bnbt/dstate.bnbt
+downloader_timeout_interval = 2700
+favicon = 
+image_bar_fill = 
+image_bar_trans = 
+keep_dead = 0
+max_give = 200
+min_announce_interval = 1500
+min_request_interval = 18000
+mysql_cbtt_ttrader_support = 0
+mysql_database = bnbt
+mysql_host = 
+mysql_override_dstate = 0
+mysql_password = 
+mysql_port = 0
+mysql_refresh_allowed_interval = 0
+mysql_refresh_stats_interval = 600
+mysql_user = 
+only_local_override_ip = 0
+parse_allowed_interval = 0
+port = 80
+response_size = 50
+save_dfile_interval = 300
+show_names = 1
+socket_timeout = 15
diff --git a/bnbt.cpp b/bnbt.cpp
new file mode 100644 (file)
index 0000000..a903f32
--- /dev/null
+++ b/bnbt.cpp
@@ -0,0 +1,550 @@
+/***\r
+*\r
+* BNBT Beta 8.0 - A C++ BitTorrent Tracker\r
+* Copyright (C) 2003-2004 Trevor Hogan\r
+*\r
+* CBTT variations (C) 2003-2005 Harold Feit\r
+*\r
+* This library is free software; you can redistribute it and/or\r
+* modify it under the terms of the GNU Lesser General Public\r
+* License as published by the Free Software Foundation; either\r
+* version 2.1 of the License, or (at your option) any later version.\r
+*\r
+* This library is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+* Lesser General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU Lesser General Public\r
+* License along with this library; if not, write to the Free Software\r
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+*\r
+***/\r
+\r
+#include <signal.h>\r
+\r
+#include "bnbt.h"\r
+#include "bnbt_mysql.h"\r
+#include "config.h"\r
+#include "link.h"\r
+#include "server.h"\r
+\r
+#include <sys/types.h>\r
+#include <sys/stat.h>\r
+#include <pwd.h>\r
+#include <fcntl.h>\r
+\r
+#ifdef WIN32\r
+ #include "util_ntservice.h"\r
+#endif\r
+\r
+#include "util.h"\r
+\r
+#ifndef WIN32\r
+ int GetLastError( ) { return errno; }\r
+#endif\r
+\r
+time_t giStartTime;\r
+\r
+unsigned long GetTime( )\r
+{\r
+       return (unsigned long)( time( NULL ) - giStartTime );\r
+}\r
+\r
+unsigned long GetRealTime( )\r
+{\r
+       return (unsigned long)( time( NULL ) );\r
+}\r
+\r
+CServer *gpServer;\r
+CLink *gpLink;\r
+CLinkServer *gpLinkServer;\r
+CMutex gmtxOutput;\r
+string gstrErrorLogDir;\r
+string gstrErrorLogFilePattern;\r
+string gstrErrorLogFile;\r
+FILE *gpErrorLog;\r
+string gstrAccessLogDir;\r
+string gstrAccessLogFilePattern;\r
+string gstrAccessLogFile;\r
+FILE *gpAccessLog;\r
+unsigned long giErrorLogCount;\r
+unsigned long giAccessLogCount;\r
+int giFlushInterval;\r
+bool gbDebug;\r
+unsigned int giMaxConns;\r
+unsigned int giMaxRecvSize;\r
+string gstrStyle;\r
+string gstrCharSet;\r
+string gstrRealm;\r
+\r
+// TCP window size\r
+int giSO_SNDBUF;\r
+int giSO_RECBUF;\r
+\r
+void sigCatcher( int sig )\r
+{\r
+       signal( SIGABRT, sigCatcher );\r
+       signal( SIGINT, sigCatcher );\r
+       // 2006/12/04 and SIGTERM and SIGHUP\r
+       signal( SIGTERM, sigCatcher );\r
+#ifndef WIN32\r
+       signal( SIGHUP, sigCatcher );\r
+#endif\r
+\r
+       if( gpServer )\r
+       {\r
+               if( gpServer->isDying( ) )\r
+                       exit( 1 );\r
+               else\r
+                       gpServer->Kill( );\r
+       }\r
+       else\r
+               exit( 1 );\r
+}\r
+\r
+int main( int argc, char *argv[] )\r
+{\r
+#ifdef WIN32\r
+       if( argv[0] )\r
+       {\r
+               char *szEndPos = strrchr( argv[0], '\\' );\r
+\r
+               if( szEndPos )\r
+               {\r
+                       char *szEXEPath = new char[szEndPos - argv[0] + 1];\r
+                       memcpy( szEXEPath, argv[0], szEndPos - argv[0] );\r
+                       szEXEPath[szEndPos - argv[0]] = '\0';\r
+\r
+                       SetCurrentDirectory( szEXEPath );\r
+\r
+                       delete [] szEXEPath;\r
+               }\r
+       }\r
+\r
+       if( argc > 1 )\r
+       {\r
+               CFG_Open( CFG_FILE );\r
+               #define BNBT_SERVICE_NAME const_cast<LPSTR> (CFG_GetString( "cbtt_service_name", "CBTT Service" ).c_str())\r
+               CFG_Close( CFG_FILE );\r
+\r
+               printf( "Service name ");\r
+               printf( BNBT_SERVICE_NAME );\r
+               printf( "\n" ); \r
+\r
+               if( _stricmp( argv[1], "-i" ) == 0 )\r
+               {\r
+                       // install service\r
+\r
+                       if( UTIL_NTServiceTest( ) )\r
+                               printf( "BNBT Service is already installed!\n" );\r
+                       else\r
+                       {\r
+                               if( UTIL_NTServiceInstall( ) )\r
+                                       printf( "BNBT Service installed.\n" );\r
+                               else\r
+                                       printf( "BNBT Service failed to install (error %d).\n", GetLastError( ) );\r
+                       }\r
+\r
+                       return 0;\r
+               }\r
+               else if( _stricmp( argv[1], "-u" ) == 0 )\r
+               {\r
+                       // uninstall service\r
+\r
+                       if( !UTIL_NTServiceTest( ) )\r
+                               printf( "BNBT Service is not installed!\n" );\r
+                       else\r
+                       {\r
+                               if( UTIL_NTServiceUninstall( ) )\r
+                                       printf( "BNBT Service uninstalled.\n" );\r
+                               else\r
+                                       printf( "BNBT Service failed to uninstall (error %d).\n", GetLastError( ) );\r
+                       }\r
+\r
+                       return 0;\r
+               }\r
+               else if( _stricmp( argv[1], "-start" ) == 0 )\r
+               {\r
+                       // start\r
+\r
+                       if( !UTIL_NTServiceTest( ) )\r
+                               printf( "BNBT Service is not installed!\n" );\r
+                       else\r
+                       {\r
+                               printf( "Starting BNBT Service.\n" );\r
+\r
+                               if( !UTIL_NTServiceStart( ) )\r
+                                       printf( "BNBT Service failed to start (error %d).\n", GetLastError( ) );\r
+                       }\r
+\r
+                       return 0;\r
+               }\r
+               else if( _stricmp( argv[1], "-stop" ) == 0 )\r
+               {\r
+                       // stop\r
+\r
+                       if( !UTIL_NTServiceTest( ) )\r
+                               printf( "BNBT Service is not installed!\n" );\r
+                       else\r
+                       {\r
+                               printf( "Stopping BNBT Service.\n" );\r
+\r
+                               if( !UTIL_NTServiceStop( ) )\r
+                                       printf( "BNBT Service failed to stop (error %d).\n", GetLastError( ) );\r
+                       }\r
+\r
+                       return 0;\r
+               }\r
+               else if( _stricmp( argv[1], "-s" ) == 0 )\r
+               {\r
+                       // internal start\r
+\r
+                       SERVICE_TABLE_ENTRY st[] = {\r
+                               { BNBT_SERVICE_NAME, NTServiceMain },\r
+                               { NULL, NULL }\r
+                       };\r
+\r
+                       StartServiceCtrlDispatcher( st );\r
+\r
+                       return 0;\r
+               }\r
+       }\r
+#else\r
+       // disable SIGPIPE since some systems like OS X don't define MSG_NOSIGNAL\r
+\r
+       signal( SIGPIPE, SIG_IGN );\r
+#endif\r
+\r
+       // catch SIGABRT and SIGINT\r
+       // 2006/12/04 and SIGTERM and SIGHUP\r
+\r
+       signal( SIGABRT, sigCatcher );\r
+       signal( SIGINT, sigCatcher );\r
+       signal( SIGTERM, sigCatcher );\r
+#ifndef WIN32\r
+       signal( SIGHUP, sigCatcher );\r
+#endif\r
+\r
+       return bnbtmain( );\r
+}\r
+\r
+#ifndef WIN32\r
+\r
+#define EXIT_SUCCESS 0\r
+#define EXIT_FAILURE 1\r
+\r
+static void sigDaemon(int signum)\r
+{\r
+    switch(signum)\r
+    {\r
+        case SIGUSR1:\r
+            exit(EXIT_SUCCESS);\r
+            break;\r
+        case SIGALRM:\r
+        case SIGCHLD:\r
+            exit(EXIT_FAILURE);\r
+            break;\r
+    }\r
+}\r
+\r
+static void daemonize( const char *lockfile )\r
+{\r
+    pid_t pid, sid, parent;\r
+    int lfp = -1;\r
+\r
+    /* already a daemon */\r
+    if ( getppid() == 1 ) return;\r
+\r
+    /* Create the lock file as the current user */\r
+    if ( lockfile && lockfile[0] ) {\r
+        lfp = open(lockfile,O_RDWR|O_CREAT,0640);\r
+        if ( lfp < 0 ) {\r
+            UTIL_LogPrint( "unable to create lock file %s, code=%d (%s)\n",\r
+                    lockfile, errno, strerror(errno) );\r
+            exit(EXIT_FAILURE);\r
+        }\r
+    }\r
+\r
+    /* Drop user if there is one, and we were run as root */\r
+    if ( getuid() == 0 || geteuid() == 0 ) {\r
+        struct passwd *pw = getpwnam(RUN_AS_USER);\r
+        if ( pw ) {\r
+            UTIL_LogPrint( "setting user to " RUN_AS_USER "\n" );\r
+            setuid( pw->pw_uid );\r
+        }\r
+    }\r
+\r
+    /* Trap signals that we expect to recieve */\r
+    signal(SIGCHLD, sigDaemon);\r
+    signal(SIGUSR1, sigDaemon);\r
+    signal(SIGALRM, sigDaemon);\r
+\r
+    /* Fork off the parent process */\r
+    pid = fork();\r
+    if (pid < 0) {\r
+        UTIL_LogPrint( "unable to fork daemon, code=%d (%s)\n",\r
+                errno, strerror(errno) );\r
+        exit(EXIT_FAILURE);\r
+    }\r
+    /* If we got a good PID, then we can exit the parent process. */\r
+    if (pid > 0) {\r
+\r
+        /* Wait for confirmation from the child via SIGTERM or SIGCHLD, \r
+or\r
+           for two seconds to elapse (SIGALRM).  pause() should not \r
+return. */\r
+        alarm(2);\r
+        pause();\r
+\r
+        exit(EXIT_FAILURE);\r
+    }\r
+\r
+    /* At this point we are executing as the child process */\r
+    parent = getppid();\r
+\r
+    /* Cancel certain signals */\r
+    signal(SIGCHLD,SIG_DFL); /* A child process dies */\r
+    signal(SIGTSTP,SIG_IGN); /* Various TTY signals */\r
+    signal(SIGTTOU,SIG_IGN);\r
+    signal(SIGTTIN,SIG_IGN);\r
+    signal(SIGHUP, SIG_IGN); /* Ignore hangup signal */\r
+    signal(SIGTERM,SIG_DFL); /* Die on SIGTERM */\r
+\r
+    /* Change the file mode mask */\r
+    umask(0);\r
+\r
+    /* Create a new SID for the child process */\r
+    sid = setsid();\r
+    if (sid < 0) {\r
+        UTIL_LogPrint( "unable to create a new session, code %d (%s)\n",\r
+                errno, strerror(errno) );\r
+        exit(EXIT_FAILURE);\r
+    }\r
+\r
+    /* Change the current working directory.  This prevents the current\r
+       directory from being locked; hence not being able to remove it. \r
+*/\r
+    if ((chdir("/")) < 0) {\r
+        UTIL_LogPrint( "unable to change directory to %s, code %d (%s)\n",\r
+                "/", errno, strerror(errno) );\r
+        exit(EXIT_FAILURE);\r
+    }\r
+\r
+    /* Redirect standard files to /dev/null */\r
+    freopen( "/dev/null", "r", stdin);\r
+    freopen( "/dev/null", "w", stdout);\r
+    freopen( "/dev/null", "w", stderr);\r
+\r
+    /* Tell the parent process that we are A-okay */\r
+    kill( parent, SIGUSR1 );\r
+}\r
+\r
+#endif // WIN32\r
+\r
+int bnbtmain( )\r
+{\r
+       gmtxOutput.Initialize( );\r
+\r
+       srand( time( NULL ) );\r
+\r
+       giStartTime = time( NULL );\r
+\r
+       CFG_Open( CFG_FILE );\r
+       CFG_SetDefaults( );\r
+       CFG_Close( CFG_FILE );\r
+\r
+       gstrErrorLogFilePattern = CFG_GetString( "bnbt_error_log_file_pattern", "%Y-%m-%de.log" );\r
+       gstrErrorLogDir = CFG_GetString( "bnbt_error_log_dir", string( ) );\r
+\r
+       if( !gstrErrorLogDir.empty( ) && gstrErrorLogDir[gstrErrorLogDir.size( ) - 1] != PATH_SEP )\r
+               gstrErrorLogDir += PATH_SEP;\r
+\r
+       gpErrorLog = NULL;\r
+       gstrAccessLogFilePattern = CFG_GetString( "bnbt_access_log_file_pattern", "%Y-%m-%d.log" );\r
+       gstrAccessLogDir = CFG_GetString( "bnbt_access_log_dir", string( ) );\r
+\r
+       if( !gstrAccessLogDir.empty( ) && gstrAccessLogDir[gstrAccessLogDir.size( ) - 1] != PATH_SEP )\r
+               gstrAccessLogDir += PATH_SEP;\r
+\r
+       gpAccessLog = NULL;\r
+       giErrorLogCount = 0;\r
+       giAccessLogCount = 0;\r
+       giFlushInterval = CFG_GetInt( "bnbt_flush_interval", 100 );\r
+       gbDebug = CFG_GetInt( "bnbt_debug", 1 ) == 0 ? false : true;\r
+       giMaxConns = CFG_GetInt( "bnbt_max_conns", 64 );\r
+       giMaxRecvSize = CFG_GetInt( "bnbt_max_recv_size", 524288 );\r
+       gstrStyle = CFG_GetString( "bnbt_style_sheet", string( ) );\r
+       gstrCharSet = CFG_GetString( "bnbt_charset", "iso-8859-1" );\r
+       gstrRealm = CFG_GetString( "bnbt_realm", "BNBT" );\r
+\r
+#ifndef WIN32\r
+    // print initial newline\r
+    printf("\n");\r
+#endif\r
+\r
+       // start winsock\r
+       \r
+       // TCP window size\r
+       giSO_RECBUF = CFG_GetInt( "xbnbt_so_recbuf", 128 ) * 1024;\r
+       giSO_SNDBUF = CFG_GetInt( "xbnbt_so_sndbuf", 128 ) * 1024;\r
+\r
+#ifdef WIN32\r
+       WSADATA wsaData;\r
+\r
+       int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );\r
+\r
+       if ( iResult != NO_ERROR )\r
+       {\r
+               UTIL_LogPrint( "error - unable to start winsock (error %d)\n", GetLastError( ) );\r
+\r
+               if( gpAccessLog )\r
+                       fclose( gpAccessLog );\r
+\r
+               if( gpErrorLog )\r
+                       fclose( gpErrorLog );\r
+\r
+               gmtxOutput.Destroy( );\r
+\r
+               return 1;\r
+       }\r
+#endif\r
+\r
+       // start mysql\r
+\r
+#ifdef BNBT_MYSQL\r
+       if( !( gpMySQL = mysql_init( NULL ) ) )\r
+       {\r
+               UTIL_LogPrint( "mysql error - %s\n", mysql_error( gpMySQL ) );\r
+\r
+               if( gpAccessLog )\r
+                       fclose( gpAccessLog );\r
+\r
+               if( gpErrorLog )\r
+                       fclose( gpErrorLog );\r
+\r
+               gmtxOutput.Destroy( );\r
+\r
+               return 1;\r
+       }\r
+\r
+       gstrMySQLHost = CFG_GetString( "mysql_host", string( ) );\r
+       gstrMySQLDatabase = CFG_GetString( "mysql_database", "bnbt" );\r
+       gstrMySQLUser = CFG_GetString( "mysql_user", string( ) );\r
+       gstrMySQLPassword = CFG_GetString( "mysql_password", string( ) );\r
+       giMySQLPort = CFG_GetInt( "mysql_port", 0 );\r
+\r
+       if( !( mysql_real_connect( gpMySQL, gstrMySQLHost.c_str( ), gstrMySQLUser.c_str( ), gstrMySQLPassword.c_str( ), gstrMySQLDatabase.c_str( ), giMySQLPort, NULL, 0 ) ) )\r
+       {\r
+               UTIL_LogPrint( "mysql error - %s\n", mysql_error( gpMySQL ) );\r
+\r
+               if( gpAccessLog )\r
+                       fclose( gpAccessLog );\r
+\r
+               if( gpErrorLog )\r
+                       fclose( gpErrorLog );\r
+\r
+               gmtxOutput.Destroy( );\r
+\r
+               return 1;\r
+       }\r
+\r
+       UTIL_LogPrint( "mysql - connected\n" );\r
+#endif\r
+\r
+       gpServer = new CServer( );\r
+       gpLink = NULL;\r
+       gpLinkServer = NULL;\r
+\r
+       if( CFG_GetInt( "bnbt_tlink_server", 0 ) != 0 )\r
+               gpLinkServer = new CLinkServer( );\r
+       else\r
+       {\r
+               if( !CFG_GetString( "bnbt_tlink_connect", string( ) ).empty( ) )\r
+               {\r
+#ifdef WIN32\r
+                       if( _beginthread( ( void (*)(void *) )StartLink, 0, NULL ) == -1 )\r
+                               UTIL_LogPrint( "error - unable to spawn link thread\n" );\r
+#else\r
+                       pthread_t thread;\r
+\r
+                       // set detached state since we don't need to join with any threads\r
+\r
+                       pthread_attr_t attr;\r
+                       pthread_attr_init( &attr );\r
+                       pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_DETACHED );\r
+\r
+                       int c = pthread_create( &thread, &attr, ( void * (*)(void *) )StartLink, NULL );\r
+\r
+                       if( c != 0 )\r
+                               UTIL_LogPrint( "error - unable to spawn link thread (error %s)\n", strerror( c ) );\r
+#endif\r
+               }\r
+       }\r
+\r
+#ifndef WIN32\r
+    // daemonize\r
+    daemonize("/var/lock/" DAEMON_NAME);\r
+#endif\r
+\r
+       while( 1 )\r
+       {\r
+               if( gpServer->Update( true ) )\r
+               {\r
+                       delete gpServer;\r
+\r
+                       gpServer = NULL;\r
+\r
+                       if( gpLinkServer )\r
+                       {\r
+                               delete gpLinkServer;\r
+\r
+                               gpLinkServer = NULL;\r
+                       }\r
+\r
+                       break;\r
+               }\r
+\r
+               if( gpLinkServer )\r
+                       gpLinkServer->Update( );\r
+       }\r
+\r
+       // wait for the link or it might make a big mess\r
+\r
+       if( gpLink )\r
+               gpLink->Kill( );\r
+\r
+       unsigned long iStart = GetTime( );\r
+\r
+       while( gpLink )\r
+       {\r
+               UTIL_LogPrint( "server - waiting for link to disconnect\n" );\r
+\r
+               MILLISLEEP( 1000 );\r
+\r
+               if( GetTime( ) - iStart > 60 )\r
+               {\r
+                       UTIL_LogPrint( "server - waited 60 seconds, exiting anyway\n" );\r
+\r
+                       break;\r
+               }\r
+       }\r
+\r
+#ifdef BNBT_MYSQL\r
+       mysql_close( gpMySQL );\r
+#endif\r
+\r
+       if( gpAccessLog )\r
+               fclose( gpAccessLog );\r
+\r
+       if( gpErrorLog )\r
+               fclose( gpErrorLog );\r
+\r
+       gmtxOutput.Destroy( );\r
+\r
+#ifdef WIN32\r
+       WSACleanup( );\r
+#endif\r
+\r
+       return 0;\r
+}\r
diff --git a/bnbt.h b/bnbt.h
new file mode 100644 (file)
index 0000000..225d9d4
--- /dev/null
+++ b/bnbt.h
@@ -0,0 +1,231 @@
+//\r
+// Copyright (C) 2003-2004 Trevor Hogan\r
+//\r
+\r
+#ifndef BNBT_H\r
+ #define BNBT_H\r
+\r
+#include <stdio.h>\r
+#include <time.h>\r
+\r
+#ifdef WIN32\r
+ #define WIN32_LEAN_AND_MEAN\r
+#endif\r
+\r
+//\r
+// SOLARIS USERS - IF YOUR SYSTEM IS LITTLE ENDIAN, REMOVE THE NEXT 3 LINES\r
+//  also see sha1.h\r
+//\r
+\r
+#if defined( __APPLE__ ) || defined( __SOLARIS__ )\r
+ #define BNBT_BIG_ENDIAN\r
+#endif\r
+\r
+#include <iostream>\r
+\r
+// large integers\r
+\r
+#ifdef WIN32\r
+ typedef __int64 int64;\r
+ typedef unsigned __int64 uint64;\r
+#else\r
+ typedef long long int64;\r
+ typedef unsigned long long uint64;\r
+#endif\r
+\r
+// stl\r
+\r
+#ifdef WIN32\r
+ #pragma warning( disable : 4786 )\r
+#endif\r
+\r
+#include <algorithm>\r
+#include <map>\r
+#include <string>\r
+#include <vector>\r
+#include <utility>\r
+\r
+using namespace std;\r
+\r
+// path seperator\r
+\r
+#ifdef WIN32\r
+ #define PATH_SEP '\\'\r
+#else\r
+ #define PATH_SEP '/'\r
+#endif\r
+\r
+// this fixes MSVC loop scoping issues\r
+\r
+/*\r
+\r
+#ifdef WIN32\r
+ #define for if( 0 ) { } else for\r
+#endif\r
+\r
+*/\r
+\r
+// time stuff\r
+\r
+unsigned long GetTime( );\r
+unsigned long GetRealTime( );\r
+\r
+#ifdef WIN32\r
+ #define MILLISLEEP( x ) Sleep( x )\r
+#else\r
+ #define MILLISLEEP( x ) usleep( ( x ) * 1000 )\r
+#endif\r
+\r
+// mutex\r
+\r
+#ifdef WIN32\r
+ #include <windows.h>\r
+ #include <process.h>\r
+#else\r
+ #include <pthread.h>\r
+#endif\r
+\r
+class CMutex\r
+{\r
+public:\r
+#ifdef WIN32\r
+       void Initialize( ) { InitializeCriticalSection( &cs ); }\r
+       void Destroy( ) { DeleteCriticalSection( &cs ); }\r
+       void Claim( ) { EnterCriticalSection( &cs ); }\r
+       void Release( ) { LeaveCriticalSection( &cs ); }\r
+\r
+       CRITICAL_SECTION cs;\r
+#else\r
+       void Initialize( ) { pthread_mutex_init( &mtx, NULL ); }\r
+       void Destroy( ) { pthread_mutex_destroy( &mtx ); }\r
+       void Claim( ) { pthread_mutex_lock( &mtx ); }\r
+       void Release( ) { pthread_mutex_unlock( &mtx ); }\r
+\r
+       pthread_mutex_t mtx;\r
+#endif\r
+};\r
+\r
+// network\r
+\r
+#ifdef WIN32\r
+ #include <winsock2.h>\r
+\r
+ #define ECONNRESET WSAECONNRESET\r
+#else\r
+ #include <arpa/inet.h>\r
+ #include <netdb.h>\r
+ #include <netinet/in.h>\r
+ #include <sys/ioctl.h>\r
+ #include <sys/socket.h>\r
+ #include <sys/types.h>\r
+ #include <unistd.h>\r
+\r
+ #include <errno.h>\r
+\r
+ typedef int SOCKET;\r
+\r
+ #define INVALID_SOCKET -1\r
+ #define SOCKET_ERROR -1\r
+ #define TCP_NODELAY 1\r
+\r
+ #define closesocket close\r
+\r
+ extern int GetLastError( );\r
+#endif\r
+\r
+#ifdef __APPLE__\r
+ typedef int socklen_t;\r
+ typedef int sockopt_len_t;\r
+#endif\r
+\r
+/*\r
+\r
+#ifdef FreeBSD\r
+ #include <sys/stat.h>\r
+#endif\r
+\r
+*/\r
+\r
+#ifndef INADDR_NONE\r
+ #define INADDR_NONE -1\r
+#endif\r
+\r
+#ifndef MSG_NOSIGNAL\r
+ #define MSG_NOSIGNAL 0\r
+#endif\r
+\r
+class CAtom;\r
+class CAtomInt;\r
+class CAtomLong;\r
+class CAtomString;\r
+class CAtomList;\r
+class CAtomDicti;\r
+\r
+class CServer;\r
+class CTracker;\r
+class CClient;\r
+\r
+class CLink;\r
+class CLinkServer;\r
+\r
+struct request_t\r
+{\r
+       struct sockaddr_in sin;\r
+       string strMethod;\r
+       string strURL;\r
+       bool hasQuery;\r
+       multimap<string, string> multiParams;\r
+       map<string, string> mapParams;\r
+       map<string, string> mapHeaders;\r
+       map<string, string> mapCookies;\r
+};\r
+\r
+struct response_t\r
+{\r
+       string strCode;\r
+       multimap<string, string> mapHeaders;\r
+       string strContent;\r
+       bool bCompressOK;\r
+};\r
+\r
+// current version\r
+\r
+#define BNBT_VER "CBTT 8.0 Core - February 2007 SVN"\r
+\r
+/*\r
+#ifdef WIN32\r
+ #define BNBT_SERVICE_NAME "BNBT Service"\r
+#endif\r
+*/\r
+\r
+extern CServer *gpServer;\r
+extern CLink *gpLink;\r
+extern CLinkServer *gpLinkServer;\r
+extern CMutex gmtxOutput;\r
+extern string gstrErrorLogDir;\r
+extern string gstrErrorLogFile;\r
+extern string gstrErrorLogFilePattern;\r
+extern FILE *gpErrorLog;\r
+extern string gstrAccessLogDir;\r
+extern string gstrAccessLogFile;\r
+extern string gstrAccessLogFilePattern;\r
+extern FILE *gpAccessLog;\r
+extern unsigned long giErrorLogCount;\r
+extern unsigned long giAccessLogCount;\r
+extern int giFlushInterval;\r
+extern bool gbDebug;\r
+extern unsigned int giMaxConns;\r
+extern unsigned int giMaxRecvSize;\r
+extern string gstrStyle;\r
+extern string gstrCharSet;\r
+extern string gstrRealm;\r
+\r
+// TCP window size\r
+extern int giSO_RECBUF;\r
+extern int giSO_SNDBUF;\r
+\r
+// this is basically the old main( ), but it's here to make the NT Service code neater\r
+\r
+extern int bnbtmain( );\r
+\r
+#endif\r
diff --git a/bnbt_mysql.cpp b/bnbt_mysql.cpp
new file mode 100644 (file)
index 0000000..8c9d106
--- /dev/null
@@ -0,0 +1,98 @@
+/***\r
+*\r
+* BNBT Beta 8.0 - A C++ BitTorrent Tracker\r
+* Copyright (C) 2003-2004 Trevor Hogan\r
+*\r
+* CBTT variations (C) 2003-2005 Harold Feit\r
+*\r
+* This library is free software; you can redistribute it and/or\r
+* modify it under the terms of the GNU Lesser General Public\r
+* License as published by the Free Software Foundation; either\r
+* version 2.1 of the License, or (at your option) any later version.\r
+*\r
+* This library is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+* Lesser General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU Lesser General Public\r
+* License along with this library; if not, write to the Free Software\r
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+*\r
+***/\r
+\r
+#ifdef BNBT_MYSQL\r
+\r
+#include "bnbt.h"\r
+#include "bnbt_mysql.h"\r
+#include "util.h"\r
+\r
+MYSQL *gpMySQL;\r
+string gstrMySQLHost;\r
+string gstrMySQLDatabase;\r
+string gstrMySQLUser;\r
+string gstrMySQLPassword;\r
+string gstrMySQLPrefix;\r
+int giMySQLPort;\r
+\r
+string UTIL_StringToMySQL( const string &strString )\r
+{\r
+       char *szMySQL = new char[strString.size( ) * 2 + 1];\r
+\r
+       if( gpMySQL )\r
+               mysql_real_escape_string( gpMySQL, szMySQL, strString.c_str( ), strString.size( ) );\r
+\r
+       string strMySQL = szMySQL;\r
+\r
+       delete [] szMySQL;\r
+\r
+       return strMySQL;\r
+}\r
+\r
+CMySQLQuery :: CMySQLQuery( string strQuery )\r
+{\r
+       mysql_real_query( gpMySQL, strQuery.c_str( ), strQuery.size( ) );\r
+\r
+       m_pRes = mysql_store_result( gpMySQL );\r
+\r
+       if( mysql_errno( gpMySQL ) )\r
+       {\r
+               m_pRes = NULL;\r
+\r
+               if( gbDebug )\r
+                       UTIL_LogPrint( "mysql error - %s\n", mysql_error( gpMySQL ) );\r
+       }\r
+}\r
+\r
+CMySQLQuery :: ~CMySQLQuery( )\r
+{\r
+       if( m_pRes )\r
+               mysql_free_result( m_pRes );\r
+}\r
+\r
+vector<string> CMySQLQuery :: nextRow( )\r
+{\r
+       vector<string> vecReturn;\r
+\r
+       if( m_pRes )\r
+       {\r
+               MYSQL_ROW row;\r
+\r
+               unsigned int num_fields = mysql_num_fields( m_pRes );\r
+               unsigned int i;\r
+\r
+               vecReturn.reserve( num_fields );\r
+\r
+               if( row = mysql_fetch_row( m_pRes ) )\r
+               {\r
+                       unsigned long *lengths = mysql_fetch_lengths( m_pRes );\r
+\r
+                       for( i = 0; i < num_fields; i++ )\r
+                               vecReturn.push_back( string( row[i], lengths[i] ) );\r
+               }\r
+       }\r
+\r
+       return vecReturn;\r
+}\r
+\r
+#endif\r
diff --git a/bnbt_mysql.h b/bnbt_mysql.h
new file mode 100644 (file)
index 0000000..e8a9b86
--- /dev/null
@@ -0,0 +1,39 @@
+//\r
+// Copyright (C) 2003-2004 Trevor Hogan\r
+//\r
+\r
+#ifdef BNBT_MYSQL\r
+\r
+#ifndef BNBT_MYSQL_H\r
+ #define BNBT_MYSQL_H\r
+\r
+#ifdef WIN32\r
+ #include <mysql.h>\r
+#else\r
+ #include <mysql/mysql.h>\r
+#endif\r
+\r
+extern MYSQL *gpMySQL;\r
+extern string gstrMySQLHost;\r
+extern string gstrMySQLDatabase;\r
+extern string gstrMySQLUser;\r
+extern string gstrMySQLPassword;\r
+extern string gstrMySQLPrefix;\r
+extern int giMySQLPort;\r
+\r
+string UTIL_StringToMySQL( const string &strString );\r
+\r
+class CMySQLQuery\r
+{\r
+public:\r
+       CMySQLQuery( string strQuery );\r
+       virtual ~CMySQLQuery( );\r
+\r
+       vector<string> nextRow( );\r
+private:\r
+       MYSQL_RES *m_pRes;\r
+};\r
+\r
+#endif\r
+\r
+#endif\r
diff --git a/client.cpp b/client.cpp
new file mode 100644 (file)
index 0000000..d83d20f
--- /dev/null
@@ -0,0 +1,671 @@
+/***\r
+*\r
+* BNBT Beta 8.0 - A C++ BitTorrent Tracker\r
+* Copyright (C) 2003-2004 Trevor Hogan\r
+*\r
+* CBTT variations (C) 2003-2005 Harold Feit\r
+*\r
+* This library is free software; you can redistribute it and/or\r
+* modify it under the terms of the GNU Lesser General Public\r
+* License as published by the Free Software Foundation; either\r
+* version 2.1 of the License, or (at your option) any later version.\r
+*\r
+* This library is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+* Lesser General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU Lesser General Public\r
+* License along with this library; if not, write to the Free Software\r
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+*\r
+***/\r
+\r
+#include "bnbt.h"\r
+#include "atom.h"\r
+#include "base64.h"\r
+#include "client.h"\r
+#include "md5.h"\r
+#include "server.h"\r
+#include "tracker.h"\r
+#include "util.h"\r
+\r
+#include <zlib.h>\r
+\r
+CClient :: CClient( SOCKET sckClient, struct sockaddr_in sinAddress, struct timeval tvTimeOut, int iCompression )\r
+{\r
+       m_sckClient = sckClient;\r
+\r
+       m_tvTimeOut = tvTimeOut;\r
+       m_iCompression = iCompression;\r
+\r
+       rqst.sin = sinAddress;\r
+       rsp.bCompressOK = true;\r
+\r
+       m_iState = CS_RECEIVING;\r
+}\r
+\r
+CClient :: ~CClient( )\r
+{\r
+       int rc = closesocket( m_sckClient );\r
+       \r
+       if( rc == SOCKET_ERROR )\r
+               UTIL_LogPrint( "client error - Closing Socket (%d)\n", GetLastError( ) );\r
+       else\r
+       {\r
+               if( gbDebug )\r
+                       UTIL_LogPrint( "client - Socket Closed\n" );\r
+       }\r
+}\r
+\r
+void CClient :: StartReceiving( )\r
+{\r
+       fd_set fdClient;\r
+\r
+       m_strReceiveBuf.erase( );\r
+       m_strReceiveBuf.reserve( 1024 );\r
+\r
+       rqst.strMethod.erase( );\r
+       rqst.strURL.erase( );\r
+       rqst.mapParams.clear( );\r
+       rqst.mapHeaders.clear( );\r
+\r
+       rsp.strCode.erase( );\r
+       rsp.mapHeaders.clear( );\r
+       rsp.strContent.erase( );\r
+       rsp.strContent.reserve( 1024 );\r
+\r
+       m_bKeepAlive = false;\r
+\r
+       while( m_strReceiveBuf.find( "\r\n\r\n" ) == string :: npos )\r
+       {\r
+               if( m_strReceiveBuf.size( ) > giMaxRecvSize )\r
+               {\r
+                       UTIL_LogPrint( "client error - exceeded max recv size\n" );\r
+\r
+                       m_iState = CS_DEAD;\r
+                       return;\r
+               }\r
+\r
+               FD_ZERO( &fdClient );\r
+               FD_SET( m_sckClient, &fdClient );\r
+\r
+#ifdef WIN32\r
+               if( select( 1, &fdClient, NULL, NULL, &m_tvTimeOut ) == SOCKET_ERROR )\r
+#else\r
+               if( select( m_sckClient + 1, &fdClient, NULL, NULL, &m_tvTimeOut ) == SOCKET_ERROR )\r
+#endif\r
+               {\r
+                       UTIL_LogPrint( "client error - select error (error %d)\n", GetLastError( ) );\r
+\r
+                       m_iState = CS_DEAD;\r
+                       return;\r
+               }\r
+\r
+               if( FD_ISSET( m_sckClient, &fdClient ) )\r
+               {\r
+                       char pTemp[8192];\r
+\r
+                       memset( pTemp, 0, sizeof( char ) * 8192 );\r
+\r
+                       // don't receive more than the buffer size\r
+\r
+                       int c = recv( m_sckClient, pTemp, 8192, 0 );\r
+\r
+                       if( c == SOCKET_ERROR )\r
+                       {\r
+                               if( GetLastError( ) != ECONNRESET )\r
+                                       UTIL_LogPrint( "client error - receive error (error %d)\n", GetLastError( ) );\r
+\r
+                               m_iState = CS_DEAD;\r
+                               return;\r
+                       }\r
+                       else if( c == 0 )\r
+                       {\r
+                               m_iState = CS_DEAD;\r
+                               return;\r
+                       }\r
+                       else if( c > 0 )\r
+                               m_strReceiveBuf += string( pTemp, c );\r
+                       else\r
+                       {\r
+                               UTIL_LogPrint( "client error - recv returned garbage\n" );\r
+\r
+                               m_iState = CS_DEAD;\r
+                               return;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       m_iState = CS_DEAD;\r
+                       return;\r
+               }\r
+       }\r
+\r
+       // grab method\r
+\r
+       string :: size_type iMethodEnd = m_strReceiveBuf.find( " " );\r
+\r
+       if( iMethodEnd == string :: npos )\r
+       {\r
+               UTIL_LogPrint( "client error - malformed HTTP request (can't find method)\n" );\r
+\r
+               m_iState = CS_DEAD;\r
+               return;\r
+       }\r
+\r
+       rqst.strMethod = m_strReceiveBuf.substr( 0, iMethodEnd );\r
+\r
+       // grab url\r
+\r
+       string strTemp = m_strReceiveBuf.substr( iMethodEnd + 1 );\r
+\r
+       string :: size_type iURLEnd = strTemp.find( " " );\r
+\r
+       if( iURLEnd == string :: npos )\r
+       {\r
+               UTIL_LogPrint( "client error - malformed HTTP request (can't find URL)\n" );\r
+\r
+               m_iState = CS_DEAD;\r
+               return;\r
+       }\r
+\r
+       strTemp = strTemp.substr( 0, iURLEnd );\r
+\r
+       string :: size_type iParamsStart = strTemp.find( "?" );\r
+\r
+       if( iParamsStart == string :: npos ){\r
+               rqst.strURL = strTemp;\r
+               rqst.hasQuery = false;\r
+       }\r
+       else {\r
+        rqst.strURL = strTemp.substr( 0, iParamsStart );\r
+               rqst.hasQuery = true;\r
+       }\r
+\r
+       // grab params\r
+       if( iParamsStart != string :: npos )\r
+       {\r
+               strTemp = strTemp.substr( iParamsStart + 1 );\r
+               rqst.hasQuery = true;\r
+\r
+               while( 1 )\r
+               {\r
+                       string :: size_type iSplit = strTemp.find( "=" );\r
+                       string :: size_type iEnd = strTemp.find( "&" );\r
+\r
+                       if ((iSplit == string::npos) && (strTemp.length() == 40)) {\r
+                               if( gbDebug )\r
+                                       UTIL_LogPrint( "Azureus-style Torrent URL passed\n" );\r
+                               rqst.mapParams.insert( pair<string, string>( string("info_hash"), strTemp) );\r
+                               strTemp = strTemp.substr( iEnd + 1, strTemp.size( ) - iEnd - 1 );\r
+                               if( iEnd == string :: npos )\r
+                                       break;\r
+                               continue;\r
+            } \r
+                       if( iSplit == string :: npos && strTemp.length() != 40 )\r
+                       {\r
+                               UTIL_LogPrint( "client warning - malformed HTTP request (found param key without value)\n" );\r
+\r
+                               break;\r
+                       }\r
+\r
+                       string strKey = UTIL_EscapedToString( strTemp.substr( 0, iSplit ) );\r
+                       string strValue = UTIL_EscapedToString( strTemp.substr( iSplit + 1, iEnd - iSplit - 1 ) );\r
+\r
+                       // multimap for scrape, regular map for everything else\r
+                       if ( rqst.strURL == "/scrape" )\r
+                               rqst.multiParams.insert( pair<string,string>( strKey, strValue ) );\r
+                       else\r
+                               rqst.mapParams.insert( pair<string, string>( strKey, strValue ) );\r
+\r
+                       strTemp = strTemp.substr( iEnd + 1, strTemp.size( ) - iEnd - 1 );\r
+\r
+                       if( iEnd == string :: npos )\r
+                               break;\r
+               }\r
+       }\r
+\r
+       // grab headers\r
+\r
+       string :: size_type iNewLine = m_strReceiveBuf.find( "\r\n" );\r
+       string :: size_type iDoubleNewLine = m_strReceiveBuf.find( "\r\n\r\n" );\r
+\r
+       strTemp = m_strReceiveBuf.substr( iNewLine + strlen( "\r\n" ), iDoubleNewLine - iNewLine - strlen( "\r\n" ) );\r
+\r
+       while( 1 )\r
+       {\r
+               string :: size_type iSplit = strTemp.find( ":" );\r
+               string :: size_type iEnd = strTemp.find( "\r\n" );\r
+\r
+               // http://www.addict3d.org/index.php?page=viewarticle&type=security&ID=4861\r
+               if( iSplit == string :: npos || iSplit == 0 || strTemp.find(": ") == string :: npos )\r
+               {\r
+                       UTIL_LogPrint( "client warning - malformed HTTP request (bad header)\n" );\r
+                       break;\r
+               }\r
+\r
+               string strKey = strTemp.substr( 0, iSplit );\r
+               string strValue = strTemp.substr( iSplit + strlen( ": " ), iEnd - iSplit - strlen( "\r\n" ) );\r
+\r
+               rqst.mapHeaders.insert( pair<string, string>( strKey, strValue ) );\r
+\r
+               strTemp = strTemp.substr( iEnd + strlen( "\r\n" ) );\r
+\r
+               if( iEnd == string :: npos )\r
+                       break;\r
+       }\r
+\r
+       // grab cookies\r
+\r
+       string strCookies = rqst.mapHeaders["Cookie"];\r
+\r
+       if( !strCookies.empty( ) )\r
+       {\r
+               while( 1 )\r
+               {\r
+                       string :: size_type iWhite = strCookies.find_first_not_of( " " );\r
+\r
+                       if( iWhite != string :: npos )\r
+                               strCookies = strCookies.substr( iWhite );\r
+\r
+                       string :: size_type iSplit = strCookies.find( "=" );\r
+                       string :: size_type iEnd = strCookies.find( ";" );\r
+\r
+                       if( iSplit == string :: npos )\r
+                       {\r
+                               UTIL_LogPrint( "client warning - malformed HTTP request (found cookie key without value)\n" );\r
+\r
+                               break;\r
+                       }\r
+\r
+                       string strKey = UTIL_EscapedToString( strCookies.substr( 0, iSplit ) );\r
+                       string strValue = UTIL_EscapedToString( strCookies.substr( iSplit + 1, iEnd - iSplit - 1 ) );\r
+\r
+                       // strip quotes\r
+\r
+                       if( strValue.size( ) > 1 && strValue[0] == '"' )\r
+                               strValue = strValue.substr( 1, strValue.size( ) - 2 );\r
+\r
+                       rqst.mapCookies.insert( pair<string, string>( strKey, strValue ) );\r
+\r
+                       strCookies = strCookies.substr( iEnd + 1, strCookies.size( ) - iEnd - 1 );\r
+\r
+                       if( iEnd == string :: npos )\r
+                               break;\r
+               }\r
+       }\r
+\r
+       // don't grab authentication here\r
+\r
+       if( rqst.strMethod == "POST" )\r
+       {\r
+               string strContentLength = rqst.mapHeaders["Content-Length"];\r
+\r
+               if( strContentLength.empty( ) )\r
+               {\r
+                       UTIL_LogPrint( "client error - malformed HTTP request (no Content-Length with POST)\n" );\r
+\r
+                       m_iState = CS_DEAD;\r
+                       return;\r
+               }\r
+\r
+               long iLength = atol( strContentLength.c_str( ) );\r
+\r
+               string :: size_type iContent = iDoubleNewLine + strlen( "\r\n\r\n" );\r
+\r
+               while( m_strReceiveBuf.size( ) < iContent + iLength )\r
+               {\r
+                       if( m_strReceiveBuf.size( ) > giMaxRecvSize )\r
+                       {\r
+                               UTIL_LogPrint( "client error - exceeded max recv size\n" );\r
+\r
+                               m_iState = CS_DEAD;\r
+                               return;\r
+                       }\r
+\r
+                       FD_ZERO( &fdClient );\r
+                       FD_SET( m_sckClient, &fdClient );\r
+\r
+#ifdef WIN32\r
+                       if( select( 1, &fdClient, NULL, NULL, &m_tvTimeOut ) == SOCKET_ERROR )\r
+#else\r
+                       if( select( m_sckClient + 1, &fdClient, NULL, NULL, &m_tvTimeOut ) == SOCKET_ERROR )\r
+#endif\r
+                       {\r
+                               UTIL_LogPrint( "client error - select error (error %d)\n", GetLastError( ) );\r
+\r
+                               m_iState = CS_DEAD;\r
+                               return;\r
+                       }\r
+\r
+                       if( FD_ISSET( m_sckClient, &fdClient ) )\r
+                       {\r
+                               char pTemp[8192];\r
+\r
+                               memset( pTemp, 0, sizeof( char ) * 8192 );\r
+\r
+                               // don't receive more than the buffer size\r
+\r
+                               int c = recv( m_sckClient, pTemp, 8192, 0 );\r
+\r
+                               if( c == SOCKET_ERROR )\r
+                               {\r
+                                       if( GetLastError( ) != ECONNRESET )\r
+                                               UTIL_LogPrint( "client error - receive error (error %d)\n", GetLastError( ) );\r
+\r
+                                       m_iState = CS_DEAD;\r
+                                       return;\r
+                               }\r
+                               else if( c == 0 )\r
+                               {\r
+                                       m_iState = CS_DEAD;\r
+                                       return;\r
+                               }\r
+                               else if( c > 0 )\r
+                                       m_strReceiveBuf += string( pTemp, c );\r
+                               else\r
+                               {\r
+                                       UTIL_LogPrint( "client error - recv returned garbage\n" );\r
+\r
+                                       m_iState = CS_DEAD;\r
+                                       return;\r
+                               }\r
+                       }\r
+                       else\r
+                       {\r
+                               m_iState = CS_DEAD;\r
+                               return;\r
+                       }\r
+               }\r
+       }\r
+\r
+       m_iState = CS_WAITING1;\r
+}\r
+\r
+void CClient :: Process( )\r
+{\r
+       m_iState = CS_PROCESSING;\r
+\r
+       // grab authentication\r
+\r
+       string strLogin = rqst.mapCookies["login"];\r
+       string strMD5 = rqst.mapCookies["md5"];\r
+\r
+       string strAuthorization = rqst.mapHeaders["Authorization"];\r
+\r
+       if( !strAuthorization.empty( ) )\r
+       {\r
+               string :: size_type iWhite = strAuthorization.find( " " );\r
+\r
+               if( iWhite != string :: npos )\r
+               {\r
+                       string strType = strAuthorization.substr( 0, iWhite );\r
+                       string strBase64 = strAuthorization.substr( iWhite + 1 );\r
+\r
+                       if( strType == "Basic" )\r
+                       {\r
+                               char *szAuth = b64decode( strBase64.c_str( ) );\r
+\r
+                               if( szAuth )\r
+                               {\r
+                                       string strAuth = szAuth;\r
+\r
+                                       free( szAuth );\r
+\r
+                                       string :: size_type iSplit = strAuth.find( ":" );\r
+\r
+                                       if( iSplit != string :: npos )\r
+                                       {\r
+                                               strLogin = strAuth.substr( 0, iSplit );\r
+                                               string strPass = strAuth.substr( iSplit + 1 );\r
+\r
+                                               // calculate md5 hash of A1\r
+\r
+                                               string strA1 = strLogin + ":" + gstrRealm + ":" + strPass;\r
+\r
+                                               unsigned char szMD5[16];\r
+\r
+                                               MD5_CTX md5;\r
+\r
+                                               MD5Init( &md5 );\r
+                                               MD5Update( &md5, (unsigned char *)strA1.c_str( ), strA1.size( ) );\r
+                                               MD5Final( szMD5, &md5 );\r
+\r
+                                               strMD5 = string( (char *)szMD5, 16 );\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+\r
+       user_t user = gpServer->getTracker( )->checkUser( strLogin, strMD5 );\r
+\r
+       // process\r
+\r
+       if( rqst.strMethod == "GET" )\r
+               gpServer->getTracker( )->serverResponseGET( &rqst, &rsp, user );\r
+       else if( rqst.strMethod == "POST" )\r
+       {\r
+               CAtomList *pPost = UTIL_DecodeHTTPPost( m_strReceiveBuf );\r
+\r
+               gpServer->getTracker( )->serverResponsePOST( &rqst, &rsp, pPost, user );\r
+\r
+               if( pPost )\r
+                       delete pPost;\r
+\r
+               pPost = NULL;\r
+       }\r
+       else\r
+               rsp.strCode = "400 Bad Request";\r
+\r
+       // compress\r
+\r
+       int iCompress = COMPRESS_NONE;\r
+\r
+       if( rsp.bCompressOK && m_iCompression > 0 )\r
+       {\r
+               string strAcceptEncoding = UTIL_ToLower( rqst.mapHeaders["Accept-Encoding"] );\r
+\r
+               if( strAcceptEncoding.find( "gzip" ) != string :: npos )\r
+                       iCompress = COMPRESS_GZIP;\r
+               else if( strAcceptEncoding.find( "deflate" ) != string :: npos )\r
+                       iCompress = COMPRESS_DEFLATE;\r
+       }\r
+\r
+       if( !rsp.strContent.empty( ) && iCompress != COMPRESS_NONE )\r
+       {\r
+               // allocate avail_in * 1.001 + 18 bytes (12 + 6 for gzip)\r
+\r
+               unsigned int iSize = (unsigned int)( rsp.strContent.size( ) * 1.001 + 18 );\r
+\r
+               unsigned char *pBuf = new unsigned char[iSize];\r
+               memset( pBuf, 0, sizeof( unsigned char ) * iSize );\r
+\r
+               z_stream_s zCompress;\r
+\r
+               zCompress.next_in = (unsigned char *)rsp.strContent.c_str( );\r
+               zCompress.avail_in = rsp.strContent.size( );\r
+               zCompress.next_out = pBuf;\r
+               zCompress.avail_out = iSize;\r
+               zCompress.zalloc = (alloc_func)0;\r
+               zCompress.zfree = (free_func)0;\r
+               zCompress.opaque = (voidpf)0;\r
+               zCompress.total_in = 0;\r
+               zCompress.total_out = 0;\r
+\r
+               int windowBits;\r
+\r
+               if( iCompress == COMPRESS_GZIP )\r
+                       windowBits = 31;\r
+               else\r
+                       windowBits = 15;\r
+\r
+               int iResult = deflateInit2( &zCompress, m_iCompression, Z_DEFLATED, windowBits, 8, Z_DEFAULT_STRATEGY );\r
+\r
+               if( iResult == Z_OK )\r
+               {\r
+                       iResult = deflate( &zCompress, Z_FINISH );\r
+\r
+                       if( iResult == Z_STREAM_END )\r
+                       {\r
+                               if( gbDebug )\r
+                                       UTIL_LogPrint( "client - (zlib) compressed %u bytes to %u bytes\n", zCompress.total_in, zCompress.total_out );\r
+\r
+                               if( iCompress == COMPRESS_GZIP )\r
+                                       rsp.mapHeaders.insert( pair<string, string>( "Content-Encoding", "gzip" ) );\r
+                               else\r
+                                       rsp.mapHeaders.insert( pair<string, string>( "Content-Encoding", "deflate" ) );\r
+\r
+                               rsp.strContent = string( (char *)pBuf, zCompress.total_out );\r
+\r
+                               deflateEnd( &zCompress );\r
+\r
+                               delete [] pBuf;\r
+                       }\r
+                       else\r
+                       {\r
+                               if( iResult != Z_OK )\r
+                                       UTIL_LogPrint( "client warning - (zlib) deflate error (%d) on \"%s\", in = %u, sending raw\n", iResult, rqst.strURL.c_str( ), rsp.strContent.size( ) );\r
+\r
+                               deflateEnd( &zCompress );\r
+\r
+                               delete [] pBuf;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       UTIL_LogPrint( "client warning - (zlib) deflateInit2 error (%d), sending raw\n", iResult );\r
+\r
+                       delete [] pBuf;\r
+               }\r
+       }\r
+\r
+       // keep alive\r
+\r
+       if( UTIL_ToLower( rqst.mapHeaders["Connection"] ) == "keep-alive" )\r
+       {\r
+               if( !gpServer->isDying( ) )\r
+               {\r
+                       m_bKeepAlive = true;\r
+\r
+                       rsp.mapHeaders.insert( pair<string, string>( "Connection", "Keep-Alive" ) );\r
+                       rsp.mapHeaders.insert( pair<string, string>( "Keep-Alive", CAtomInt( m_tvTimeOut.tv_sec - 1 ).toString( ) ) );\r
+               }\r
+               else\r
+               {\r
+                       m_bKeepAlive = false;\r
+\r
+                       rsp.mapHeaders.insert( pair<string, string>( "Connection", "Close" ) );\r
+                       rsp.mapHeaders.insert( pair<string, string>( "Keep-Alive", CAtomInt( m_tvTimeOut.tv_sec - 1 ).toString( ) ) );\r
+               }\r
+       }\r
+\r
+       rsp.mapHeaders.insert( pair<string, string>( "Content-Length", CAtomLong( rsp.strContent.size( ) ).toString( ) ) );\r
+\r
+       // access log\r
+\r
+       string strRequest;\r
+\r
+       int iNewLine = m_strReceiveBuf.find( "\r\n" );\r
+\r
+       if( iNewLine != string :: npos )\r
+               strRequest = m_strReceiveBuf.substr( 0, iNewLine );\r
+\r
+       UTIL_AccessLogPrint( inet_ntoa( rqst.sin.sin_addr ), user.strLogin, strRequest, atoi( rsp.strCode.substr( 0, 3 ).c_str( ) ), rsp.strContent.size( ) );\r
+\r
+       m_iState = CS_WAITING2;\r
+}\r
+\r
+void CClient :: StartSending( )\r
+{\r
+       fd_set fdClient;\r
+\r
+       // compose send buffer\r
+\r
+       string strSendBuf;\r
+       strSendBuf.reserve( 1024 );\r
+\r
+       strSendBuf += "HTTP/1.1 " + rsp.strCode + "\r\n";\r
+\r
+       for( multimap<string, string> :: iterator i = rsp.mapHeaders.begin( ); i != rsp.mapHeaders.end( ); i++ )\r
+               strSendBuf += (*i).first + ": " + (*i).second + "\r\n";\r
+\r
+       strSendBuf += "\r\n";\r
+       strSendBuf += rsp.strContent;\r
+\r
+       // send\r
+\r
+       while( !strSendBuf.empty( ) )\r
+       {\r
+               FD_ZERO( &fdClient );\r
+               FD_SET( m_sckClient, &fdClient );\r
+\r
+#ifdef WIN32\r
+               if( select( 1, NULL, &fdClient, NULL, &m_tvTimeOut ) == SOCKET_ERROR )\r
+#else\r
+               if( select( m_sckClient + 1, NULL, &fdClient, NULL, &m_tvTimeOut ) == SOCKET_ERROR )\r
+#endif\r
+               {\r
+                       UTIL_LogPrint( "client error - select error (error %d)\n", GetLastError( ) );\r
+\r
+                       m_iState = CS_DEAD;\r
+                       return;\r
+               }\r
+\r
+               if( FD_ISSET( m_sckClient, &fdClient ) )\r
+               {\r
+                       int s = send( m_sckClient, strSendBuf.c_str( ), strSendBuf.size( ), MSG_NOSIGNAL );\r
+\r
+                       if( s == SOCKET_ERROR )\r
+                       {\r
+                               UTIL_LogPrint( "client error - send error (error %d)\n", GetLastError( ) );\r
+\r
+                               m_iState = CS_DEAD;\r
+                               return;\r
+                       }\r
+                       else if( s == 0 )\r
+                       {\r
+                               UTIL_LogPrint( "client error - send returned 0\n" );\r
+\r
+                               m_iState = CS_DEAD;\r
+                               return;\r
+                       }\r
+                       else if( s > 0 )\r
+                               strSendBuf = strSendBuf.substr( s );\r
+                       else\r
+                       {\r
+                               UTIL_LogPrint( "client error - send returned garbage\n" );\r
+\r
+                               m_iState = CS_DEAD;\r
+                               return;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       m_iState = CS_DEAD;\r
+                       return;\r
+               }\r
+       }\r
+\r
+       if( m_bKeepAlive )\r
+       {\r
+               m_iState = CS_RECEIVING;\r
+\r
+               StartReceiving( );\r
+       }\r
+       else\r
+               m_iState = CS_DEAD;\r
+}\r
+\r
+void StartReceiving( CClient *pClient )\r
+{\r
+       if( pClient )\r
+               pClient->StartReceiving( );\r
+}\r
+\r
+void StartSending( CClient *pClient )\r
+{\r
+       if( pClient )\r
+               pClient->StartSending( );\r
+}\r
diff --git a/client.h b/client.h
new file mode 100644 (file)
index 0000000..976c837
--- /dev/null
+++ b/client.h
@@ -0,0 +1,45 @@
+//\r
+// Copyright (C) 2003-2004 Trevor Hogan\r
+//\r
+\r
+#ifndef CLIENT_H\r
+ #define CLIENT_H\r
+\r
+#define COMPRESS_NONE          0\r
+#define COMPRESS_DEFLATE       1\r
+#define COMPRESS_GZIP          2\r
+\r
+#define CS_RECEIVING           0\r
+#define CS_WAITING1                    1\r
+#define CS_PROCESSING          2\r
+#define CS_WAITING2                    3\r
+#define CS_SENDING                     4\r
+#define CS_DEAD                                5\r
+\r
+class CClient\r
+{\r
+public:\r
+       CClient( SOCKET sckClient, struct sockaddr_in sinAddress, struct timeval tvTimeOut, int iCompression );\r
+       virtual ~CClient( );\r
+\r
+       void StartReceiving( );\r
+       void Process( );\r
+       void StartSending( );\r
+\r
+       int m_iState;\r
+\r
+private:\r
+       SOCKET m_sckClient;\r
+\r
+       struct timeval m_tvTimeOut;\r
+       int m_iCompression;\r
+       string m_strReceiveBuf;\r
+       struct request_t rqst;\r
+       struct response_t rsp;\r
+       bool m_bKeepAlive;\r
+};\r
+\r
+void StartReceiving( CClient *pClient );\r
+void StartSending( CClient *pClient );\r
+\r
+#endif\r
diff --git a/config.cpp b/config.cpp
new file mode 100644 (file)
index 0000000..5baee95
--- /dev/null
@@ -0,0 +1,615 @@
+/***\r
+*\r
+* BNBT Beta 8.0 - A C++ BitTorrent Tracker\r
+* Copyright (C) 2003-2004 Trevor Hogan\r
+*\r
+* CBTT variations (C) 2003-2005 Harold Feit\r
+*\r
+* This library is free software; you can redistribute it and/or\r
+* modify it under the terms of the GNU Lesser General Public\r
+* License as published by the Free Software Foundation; either\r
+* version 2.1 of the License, or (at your option) any later version.\r
+*\r
+* This library is distributed in the hope that it will be useful,\r
+* but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+* Lesser General Public License for more details.\r
+*\r
+* You should have received a copy of the GNU Lesser General Public\r
+* License along with this library; if not, write to the Free Software\r
+* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+*\r
+***/\r
+\r
+#include <fstream>\r
+\r
+#include "bnbt.h"\r
+#include "atom.h"\r
+#include "config.h"\r
+#include "tracker.h"\r
+#include "util.h"\r
+\r
+map<string, string> gmapCFG;\r
+\r
+void CFG_Open( const char *szFile )\r
+{\r
+       gmapCFG.clear( );\r
+\r
+       ifstream in;\r
+\r
+       in.open( szFile );\r
+\r
+       if( in.fail( ) )\r
+       {\r
+               UTIL_LogPrint( "config warning - unable to open %s for reading\n", szFile );\r
+\r
+               return;\r
+       }\r
+\r
+       while( !in.eof( ) )\r
+       {\r
+               char pBuf[1024];\r
+\r
+               in.getline( pBuf, 1023 );\r
+\r
+               string strTemp = pBuf;\r
+\r
+               // ignore blank lines and comments\r
+\r
+               if( strTemp.empty( ) || strTemp[0] == '#' )\r
+                       continue;\r
+\r
+               string :: size_type iSplit = strTemp.find( "=" );\r
+\r
+               if( iSplit == string :: npos )\r
+                       continue;\r
+\r
+               string :: size_type iKeyStart = strTemp.find_first_not_of( " " );\r
+               string :: size_type iKeyEnd = strTemp.find( " ", iKeyStart );\r
+               string :: size_type iValueStart = strTemp.find_first_not_of( " ", iSplit + 1 );\r
+               string :: size_type iValueEnd = strTemp.size( );\r
+\r
+               if( iValueStart != string :: npos )\r
+                       gmapCFG[strTemp.substr( iKeyStart, iKeyEnd - iKeyStart )] = strTemp.substr( iValueStart, iValueEnd - iValueStart );\r
+       }\r
+\r
+       in.close( );\r
+}\r
+\r
+void CFG_SetInt( string strKey, int x )\r
+{\r
+       gmapCFG[strKey] = CAtomInt( x ).toString( );\r
+}\r
+\r
+void CFG_SetString( string strKey, string x )\r
+{\r
+       gmapCFG[strKey] = x;\r
+}\r
+\r
+int CFG_GetInt( string strKey, int x )\r
+{\r
+       if( gmapCFG.find( strKey ) == gmapCFG.end( ) )\r
+               return x;\r
+       else\r
+               return atoi( gmapCFG[strKey].c_str( ) );\r
+}\r
+\r
+string CFG_GetString( string strKey, string x )\r
+{\r
+       if( gmapCFG.find( strKey ) == gmapCFG.end( ) )\r
+               return x;\r
+       else\r
+               return gmapCFG[strKey];\r
+}\r
+\r
+void CFG_Delete( string strKey )\r
+{\r
+       gmapCFG.erase( strKey );\r
+}\r
+\r
+void CFG_Close( const char *szFile )\r
+{\r
+       ofstream out;\r
+\r
+       out.open( szFile );\r
+\r
+       if( out.fail( ) )\r
+       {\r
+               UTIL_LogPrint( "config warning - unable to open %s for writing\n", szFile );\r
+\r
+               return;\r
+       }\r
+\r
+       for( map<string, string> :: iterator i = gmapCFG.begin( ); i != gmapCFG.end( ); i++ )\r
+               out << (*i).first.c_str( ) << " = " << (*i).second.c_str( ) << endl;\r
+\r
+       out.close( );\r
+}\r
+\r
+void CFG_SetDefaults( )\r
+{\r
+       if( gbDebug )\r
+               UTIL_LogPrint( "config - setting defaults\n" );\r
+\r
+       // bnbt.cpp\r
+\r
+       if( CFG_GetInt( "bnbt_debug", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_debug", 0 );\r
+\r
+       if( CFG_GetInt( "bnbt_max_conns", 0 ) < 1 )\r
+               CFG_SetInt( "bnbt_max_conns", 64 );\r
+\r
+       if( CFG_GetString( "bnbt_style_sheet", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_style_sheet", string( ) );\r
+\r
+       if( CFG_GetString( "bnbt_charset", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_charset", "iso-8859-1" );\r
+\r
+       if( CFG_GetString( "bnbt_realm", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_realm", "BNBT" );\r
+\r
+       if( CFG_GetString( "bnbt_error_log_dir", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_error_log_dir", string( ) );\r
+\r
+       if( CFG_GetString( "bnbt_error_log_file_pattern", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_error_log_file_pattern", "%Y-%m-%de.log" );\r
+\r
+       if( CFG_GetString( "bnbt_access_log_dir", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_access_log_dir", string( ) );\r
+\r
+       if( CFG_GetString( "bnbt_access_log_file_pattern", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_access_log_file_pattern", "%Y-%m-%d.log" );\r
+\r
+       if( CFG_GetInt( "bnbt_flush_interval", 0 ) < 1 )\r
+               CFG_SetInt( "bnbt_flush_interval", 100 );\r
+\r
+       // mysql\r
+\r
+       if( CFG_GetString( "mysql_host", string( ) ).empty( ) )\r
+               CFG_SetString( "mysql_host", string( ) );\r
+\r
+       if( CFG_GetString( "mysql_database", string( ) ).empty( ) )\r
+               CFG_SetString( "mysql_database", "bnbt" );\r
+\r
+       if( CFG_GetString( "mysql_user", string( ) ).empty( ) )\r
+               CFG_SetString( "mysql_user", string( ) );\r
+\r
+       if( CFG_GetString( "mysql_password", string( ) ).empty( ) )\r
+               CFG_SetString( "mysql_password", string( ) );\r
+\r
+       if( CFG_GetInt( "mysql_port", -1 ) < 0 )\r
+               CFG_SetInt( "mysql_port", 0 );\r
+\r
+       if( CFG_GetInt( "mysql_refresh_allowed_interval", -1 ) < 0 )\r
+               CFG_SetInt( "mysql_refresh_allowed_interval", 0 );\r
+\r
+       if( CFG_GetInt( "mysql_refresh_stats_interval", 0 ) < 1 )\r
+               CFG_SetInt( "mysql_refresh_stats_interval", 600 );\r
+\r
+       if( CFG_GetInt( "mysql_override_dstate", -1 ) < 0 )\r
+               CFG_SetInt( "mysql_override_dstate", 0 );\r
+\r
+       // link.cpp\r
+\r
+       if( CFG_GetInt( "bnbt_tlink_server", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_tlink_server", 0 );\r
+\r
+       if( CFG_GetString( "bnbt_tlink_connect", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_tlink_connect", string( ) );\r
+\r
+       if( CFG_GetString( "bnbt_tlink_password", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_tlink_password", string( ) );\r
+\r
+       if( CFG_GetString( "bnbt_tlink_bind", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_tlink_bind", string( ) );\r
+\r
+       if( CFG_GetInt( "bnbt_tlink_port", 0 ) < 1 )\r
+               CFG_SetInt( "bnbt_tlink_port", 5204 );\r
+\r
+       // server.cpp\r
+\r
+       if( CFG_GetInt( "socket_timeout", 0 ) < 1 )\r
+               CFG_SetInt( "socket_timeout", 15 );\r
+\r
+       if( CFG_GetInt( "bnbt_compression_level", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_compression_level", 6 );\r
+\r
+       if( CFG_GetString( "bind", string( ) ).empty( ) )\r
+               CFG_SetString( "bind", string( ) );\r
+\r
+       if( CFG_GetInt( "port", 0 ) < 1 )\r
+               CFG_SetInt( "port", 26213 );\r
+\r
+       // tracker.cpp\r
+\r
+       if( CFG_GetString( "allowed_dir", string( ) ).empty( ) )\r
+               CFG_SetString( "allowed_dir", string( ) );\r
+\r
+       if( CFG_GetString( "bnbt_upload_dir", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_upload_dir", string( ) );\r
+\r
+       if( CFG_GetString( "bnbt_external_torrent_dir", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_external_torrent_dir", string( ) );\r
+\r
+       if( CFG_GetString( "bnbt_archive_dir", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_archive_dir", string( ) );\r
+\r
+       if( CFG_GetString( "bnbt_file_dir", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_file_dir", string( ) );\r
+\r
+       if( CFG_GetString( "dfile", string( ) ).empty( ) )\r
+               CFG_SetString( "dfile", "dstate.bnbt" );\r
+\r
+       if( CFG_GetString( "bnbt_comments_file", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_comments_file", string( ) );\r
+\r
+       if( CFG_GetString( "bnbt_tag_file", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_tag_file", "tags.bnbt" );\r
+\r
+       if( CFG_GetString( "bnbt_users_file", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_users_file", "users.bnbt" );\r
+\r
+       if( CFG_GetString( "bnbt_static_header", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_static_header", string( ) );\r
+\r
+       if( CFG_GetString( "bnbt_static_footer", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_static_footer", string( ) );\r
+\r
+       if( CFG_GetString( "bnbt_robots_txt", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_robots_txt", string( ) );\r
+\r
+       if( CFG_GetString( "bnbt_dump_xml_file", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_dump_xml_file", string( ) );\r
+\r
+       if( CFG_GetString( "image_bar_fill", string( ) ).empty( ) )\r
+               CFG_SetString( "image_bar_fill", string( ) );\r
+\r
+       if( CFG_GetString( "image_bar_trans", string( ) ).empty( ) )\r
+               CFG_SetString( "image_bar_trans", string( ) );\r
+\r
+       if( CFG_GetString( "bnbt_force_announce_url", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_force_announce_url", string( ) );\r
+\r
+       if( CFG_GetInt( "bnbt_force_announce_on_download", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_force_announce_on_download", 0 );\r
+\r
+       if( CFG_GetInt( "parse_allowed_interval", -1 ) < 0 )\r
+               CFG_SetInt( "parse_allowed_interval", 0 );\r
+\r
+       if( CFG_GetInt( "save_dfile_interval", 0 ) < 1 )\r
+               CFG_SetInt( "save_dfile_interval", 300 );\r
+\r
+       if( CFG_GetInt( "downloader_timeout_interval", 0 ) < 1 )\r
+               CFG_SetInt( "downloader_timeout_interval", 2700 );\r
+\r
+       if( CFG_GetInt( "bnbt_refresh_static_interval", 0 ) < 1 )\r
+               CFG_SetInt( "bnbt_refresh_static_interval", 10 );\r
+\r
+       if( CFG_GetInt( "bnbt_dump_xml_interval", 0 ) < 1 )\r
+               CFG_SetInt( "bnbt_dump_xml_interval", 600 );\r
+\r
+       if( CFG_GetInt( "bnbt_dump_xml_peers", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_dump_xml_peers", 1 );\r
+\r
+       if( CFG_GetInt( "announce_interval", -1 ) < 0 )\r
+               CFG_SetInt( "announce_interval", 1800 );\r
+\r
+       if( CFG_GetInt( "min_request_interval", -1 ) < 0 )\r
+               CFG_SetInt( "min_request_interval", 18000 );\r
+\r
+       if( CFG_GetInt( "response_size", -1 ) < 0 )\r
+               CFG_SetInt( "response_size", 50 );\r
+\r
+       if( CFG_GetInt( "max_give", -1 ) < 0 )\r
+               CFG_SetInt( "max_give", 200 );\r
+\r
+       if( CFG_GetInt( "keep_dead", -1 ) < 0 )\r
+               if( CFG_GetInt( "bnbt_display_all", -1) >= 0 ){\r
+                       if( CFG_GetInt( "bnbt_display_all", -1) == 0 )\r
+                               CFG_SetInt( "keep_dead", 0 );\r
+                       else if( CFG_GetInt( "bnbt_display_all", -1) == 1 )\r
+                               CFG_SetInt( "keep_dead", 1 );\r
+               }\r
+               else\r
+                       CFG_SetInt( "keep_dead", 0 );\r
+\r
+       if( CFG_GetInt( "bnbt_allow_scrape", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_allow_scrape", 1 );\r
+\r
+       if( CFG_GetInt( "bnbt_count_unique_peers", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_count_unique_peers", 1 );\r
+\r
+       if( CFG_GetInt( "bnbt_delete_invalid", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_delete_invalid", 0 );\r
+\r
+       if( CFG_GetInt( "bnbt_parse_on_upload", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_parse_on_upload", 1 );\r
+\r
+       if( CFG_GetInt( "bnbt_max_torrents", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_max_torrents", 0 );\r
+\r
+       if( CFG_GetInt( "bnbt_show_info_hash", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_show_info_hash", 0 );\r
+\r
+       if( CFG_GetInt( "show_names", -1 ) < 0 )\r
+               CFG_SetInt( "show_names", 1 );\r
+\r
+       if( CFG_GetInt( "bnbt_show_stats", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_show_stats", 1 );\r
+\r
+       if( CFG_GetInt( "bnbt_allow_torrent_downloads", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_allow_torrent_downloads", 1 );\r
+\r
+       if( CFG_GetInt( "bnbt_allow_comments", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_allow_comments", 0 );\r
+\r
+       if( CFG_GetInt( "bnbt_show_added", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_show_added", 1 );\r
+\r
+       if( CFG_GetInt( "bnbt_show_size", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_show_size", 1 );\r
+\r
+       if( CFG_GetInt( "bnbt_show_num_files", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_show_num_files", 1 );\r
+\r
+       if( CFG_GetInt( "bnbt_show_completed", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_show_completed", 0 );\r
+\r
+       if( CFG_GetInt( "bnbt_show_transferred", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_show_transferred", 0 );\r
+\r
+       if( CFG_GetInt( "bnbt_show_min_left", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_show_min_left", 0 );\r
+\r
+       if( CFG_GetInt( "bnbt_show_average_left", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_show_average_left", 0 );\r
+\r
+       if( CFG_GetInt( "bnbt_show_max_left", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_show_max_left", 0 );\r
+\r
+       if( CFG_GetInt( "bnbt_show_left_as_progress", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_show_left_as_progress", 1 );\r
+\r
+       if( CFG_GetInt( "bnbt_show_uploader", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_show_uploader", 0 );\r
+\r
+       if( CFG_GetInt( "bnbt_allow_info_link", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_allow_info_link", 0 );\r
+\r
+       if( CFG_GetInt( "bnbt_allow_search", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_allow_search", 1 );\r
+\r
+       if( CFG_GetInt( "bnbt_allow_sort", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_allow_sort", 1 );\r
+\r
+       if( CFG_GetInt( "bnbt_show_file_comment", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_show_file_comment", 1 );\r
+\r
+       if( CFG_GetInt( "bnbt_show_file_contents", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_show_file_contents", 0 );\r
+\r
+       if( CFG_GetInt( "bnbt_show_share_ratios", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_show_share_ratios", 1 );\r
+\r
+       if( CFG_GetInt( "bnbt_show_average_dl_rate", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_show_average_dl_rate", 0 );\r
+\r
+       if( CFG_GetInt( "bnbt_show_average_ul_rate", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_show_average_ul_rate", 0 );\r
+\r
+       if( CFG_GetInt( "bnbt_delete_own_torrents", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_delete_own_torrents", 1 );\r
+\r
+       if( CFG_GetInt( "bnbt_show_gen_time", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_show_gen_time", 1 );\r
+\r
+       if( CFG_GetInt( "bnbt_per_page", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_per_page", 20 );\r
+\r
+       if( CFG_GetInt( "bnbt_users_per_page", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_users_per_page", 50 );\r
+\r
+       if( CFG_GetInt( "bnbt_max_peers_display", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_max_peers_display", 500 );\r
+\r
+       if( CFG_GetInt( "bnbt_guest_access", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_guest_access", ACCESS_VIEW | ACCESS_DL | ACCESS_SIGNUP );\r
+\r
+       if( CFG_GetInt( "bnbt_member_access", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_member_access", ACCESS_VIEW | ACCESS_DL | ACCESS_COMMENTS | ACCESS_UPLOAD | ACCESS_SIGNUP );\r
+\r
+       if( CFG_GetInt( "bnbt_file_expires", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_file_expires", 180 );\r
+\r
+       if( CFG_GetInt( "bnbt_name_length", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_name_length", 32 );\r
+\r
+       if( CFG_GetInt( "bnbt_comment_length", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_comment_length", 800 );\r
+\r
+       if( CFG_GetInt( "bnbt_max_recv_size", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_max_recv_size", 524288 );\r
+\r
+       // CBTT values\r
+       if( CFG_GetInt( "cbtt_ban_mode", -1 ) < 0 )\r
+               CFG_SetInt( "cbtt_ban_mode", 0 );\r
+\r
+       if( CFG_GetInt( "cbtt_restricted_peer_spoofing", -1 ) < 0 )\r
+               CFG_SetInt( "cbtt_restricted_peer_spoofing", 0 );\r
+\r
+       if( CFG_GetString( "cbtt_ban_file", string( ) ).empty( ) )\r
+               CFG_SetString( "cbtt_ban_file", "clientbans.bnbt" );\r
+\r
+       if( CFG_GetString( "cbtt_service_name", string() ).empty() )\r
+               if( !CFG_GetString( "trinity_nt_service_name",string()).empty() )\r
+                       CFG_SetString( "cbtt_service_name", CFG_GetString( "trinity_nt_service_name",string()) );\r
+               else\r
+                       CFG_SetString( "cbtt_service_name", "BNBT Service" );\r
+               \r
+       if( CFG_GetInt( "cbtt_ip_ban_mode", -1 ) < 0 )\r
+               CFG_SetInt( "cbtt_ip_ban_mode", 0 );\r
+\r
+       if( CFG_GetString( "cbtt_ipban_file", string( ) ).empty( ) )\r
+               CFG_SetString( "cbtt_ipban_file", "bans.bnbt" );\r
+\r
+       if( CFG_GetInt( "cbtt_dont_compress_torrents", -1 ) < 0 )\r
+               CFG_SetInt( "cbtt_dont_compress_torrents", 0 );\r
+\r
+       if( CFG_GetInt( "cbtt_restrict_overflow", -1 ) <0 )\r
+               CFG_SetInt( "cbtt_restrict_overflow", 0 );\r
+\r
+       if( CFG_GetString( "cbtt_restrict_overflow_limit", string( ) ).empty( ) )\r
+               CFG_SetString( "cbtt_restrict_overflow_limit", "1099511627776" );\r
+\r
+       if( CFG_GetInt( "cbtt_block_private_ip", -1 ) < 0 )\r
+               if( CFG_GetInt( "bnbt_block_private_ip", -1 ) >= 0 ) {\r
+            CFG_SetInt( "cbtt_block_private_ip", CFG_GetInt( "bnbt_block_private_ip", -1 ));\r
+                       CFG_Delete( "bnbt_block_private_ip");\r
+               }\r
+               else\r
+                       CFG_SetInt( "cbtt_block_private_ip", 0 );\r
+\r
+       if( CFG_GetInt( "cbtt_blacklist_common_p2p_ports", -1) < 0)\r
+               CFG_SetInt( "cbtt_blacklist_common_p2p_ports", 0);\r
+\r
+       if( CFG_GetInt( "cbtt_blacklist_below_1024" , -1) < 0)\r
+               CFG_SetInt( "cbtt_blacklist_below_1024" , 0);\r
+\r
+       if( CFG_GetInt( "only_local_override_ip", -1 ) < 0 )\r
+               CFG_SetInt( "only_local_override_ip", 0 );\r
+\r
+       if( CFG_GetInt( "mysql_cbtt_ttrader_support", -1 ) < 0 )\r
+        CFG_SetInt( "mysql_cbtt_ttrader_support", 0 );\r
+\r
+       if( CFG_GetString( "favicon", string( ) ).empty() )\r
+               CFG_SetString( "favicon", string( ) );\r
+\r
+       if( CFG_GetInt( "bnbt_private_tracker_flag", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_private_tracker_flag", 0 );\r
+\r
+       if( CFG_GetInt( "bnbt_private_tracker_flag", -1 ) > 1)\r
+               CFG_SetInt( "bnbt_private_tracker_flag", 1 );\r
+\r
+       if( CFG_GetInt( "bnbt_swap_torrent_link", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_swap_torrent_link", 0 );\r
+\r
+       if( CFG_GetInt( "bnbt_swap_torrent_link", -1 ) > 1)\r
+               CFG_SetInt( "bnbt_swap_torrent_link", 1 );\r
+\r
+       if( CFG_GetInt( "cbtt_require_compact", -1 ) < 0 )\r
+               CFG_SetInt( "cbtt_require_compact", 0 );\r
+\r
+       if( CFG_GetInt( "cbtt_require_compact", -1 ) > 1)\r
+               CFG_SetInt( "cbtt_require_compact", 1 );\r
+\r
+       if( CFG_GetInt( "cbtt_require_no_peer_id", -1 ) < 0 )\r
+               CFG_SetInt( "cbtt_require_no_peer_id", 0 );\r
+\r
+       if( CFG_GetInt( "cbtt_require_no_peer_id", -1 ) > 1)\r
+               CFG_SetInt( "cbtt_require_no_peer_id", 1 );\r
+\r
+       if( CFG_GetInt( "bnbt_allow_scrape_global", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_allow_scrape_global", 0 );\r
+\r
+       if( CFG_GetInt( "bnbt_allow_scrape_global", -1 ) > 1)\r
+               CFG_SetInt( "bnbt_allow_scrape_global", 1 );\r
+\r
+       if( CFG_GetInt( "bnbt_use_announce_key", -1 ) != 0 )\r
+               CFG_SetInt( "bnbt_use_announce_key", 1 );\r
+\r
+       if( CFG_GetInt( "bnbt_require_announce_key", -1 ) != 0 )\r
+               CFG_SetInt( "bnbt_require_announce_key", 1 );\r
+\r
+       if( CFG_GetInt( "bnbt_disable_html", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_disable_html", 0 );\r
+\r
+       if( CFG_GetInt( "bnbt_disable_html", -1 ) > 1)\r
+               CFG_SetInt( "bnbt_disable_html", 1 );\r
+\r
+       if( CFG_GetInt( "bnbt_refresh_fast_cache_interval", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_refresh_fast_cache_interval", 30 );\r
+\r
+       if( CFG_GetInt( "min_announce_interval", -1 ) < 0 )\r
+               CFG_SetInt( "min_announce_interval", CFG_GetInt("announce_interval", 1800) / 1.2 );\r
+\r
+    if( CFG_GetInt( "cbtt_abuse_detection", -1 ) < 0 )\r
+               CFG_SetInt( "cbtt_abuse_detection", 0 );\r
+\r
+       if( CFG_GetInt( "cbtt_abuse_hammer_limit", -1 ) < 0 )\r
+               CFG_SetInt( "cbtt_abuse_hammer_limit", 10 );\r
+\r
+       if( CFG_GetInt( "cbtt_abuse_limit", -1 ) < 0 )\r
+               CFG_SetInt( "cbtt_abuse_limit", 5 );\r
+\r
+       // Creates the Tracker Title configuration key\r
+\r
+       if( CFG_GetString( "bnbt_tracker_title", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_tracker_title", string( ) );\r
+\r
+       if( CFG_GetString( "cbtt_download_link_image", string( ) ).empty( ) )\r
+               CFG_SetString( "cbtt_download_link_image", "" );\r
+\r
+       if( CFG_GetString( "cbtt_stats_link_image", string( ) ).empty( ) )\r
+               CFG_SetString( "cbtt_stats_link_image", "" );\r
+\r
+       if( CFG_GetString( "cbtt_scrape_file", string( ) ).empty() )\r
+               CFG_SetString( "cbtt_scrape_file", "" );\r
+\r
+       if( CFG_GetInt( "cbtt_scrape_save_interval", -1 ) < 0 )\r
+               CFG_SetInt( "cbtt_scrape_save_interval", 0 );\r
+\r
+       if( CFG_GetInt( "cbtt_page_number_count" , 2 ) < 3 )\r
+               CFG_SetInt( "cbtt_page_number_count", 3);\r
+\r
+       if( CFG_GetInt( "cbtt_hide_login_links", -1 ) < 0 )\r
+               CFG_SetInt( "cbtt_hide_login_links", 0 );\r
+\r
+\r
+       //RSS Feed Support - code by labarks\r
+       if( CFG_GetString( "bnbt_rss_file", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_rss_file", string( ) );\r
+               \r
+       if( CFG_GetString( "bnbt_rss_online_dir", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_rss_online_dir", string( ) );\r
+\r
+       if( CFG_GetString( "bnbt_rss_online_url", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_rss_online_url", string( ) );\r
+               \r
+       if( CFG_GetInt( "bnbt_rss_file_mode", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_rss_file_mode", 0 );\r
+               \r
+       if( CFG_GetString( "bnbt_rss_channel_title", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_rss_channel_title", "My BNBT RSS Feed" );\r
+       \r
+       if( CFG_GetString( "bnbt_rss_channel_link", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_rss_channel_link", "http://localhost:26213/" );\r
+                       \r
+       if( CFG_GetString( "bnbt_rss_channel_description", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_rss_channel_description", "BitTorrent RSS Feed for BNBT" );\r
+       \r
+       if( CFG_GetInt( "bnbt_rss_channel_ttl", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_rss_channel_ttl", 60 );\r
+       \r
+       if( CFG_GetString( "bnbt_rss_channel_language", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_rss_channel_language", "en-us" );\r
+               \r
+       if( CFG_GetString( "bnbt_rss_channel_image_url", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_rss_channel_image_url", string( ) );\r
+               \r
+       if( CFG_GetInt( "bnbt_rss_channel_image_width", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_rss_channel_image_width", 0 );\r
+\r
+       if( CFG_GetInt( "bnbt_rss_channel_image_height", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_rss_channel_image_height", 0 );\r
+       \r
+       if( CFG_GetString( "bnbt_rss_channel_copyright", string( ) ).empty( ) )\r
+               CFG_SetString( "bnbt_rss_channel_copyright", string( ) );\r
+       \r
+       if( CFG_GetInt( "bnbt_rss_limit", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_rss_limit", 25 );\r
+\r
+       if( CFG_GetInt( "bnbt_rss_interval", -1 ) < 0 )\r
+               CFG_SetInt( "bnbt_rss_interval", 30 );\r
+       //end addition\r
+\r
+}\r
diff --git a/config.h b/config.h
new file mode 100644 (file)
index 0000000..338a214
--- /dev/null
+++ b/config.h
@@ -0,0 +1,23 @@
+//\r
+// Copyright (C) 2003-2004 Trevor Hogan\r
+//\r
+\r
+#ifndef CONFIG_H\r
+ #define CONFIG_H\r
+\r
+#define CFG_FILE "/etc/bnbt.cfg"\r
+#define DAEMON_NAME "bnbt"\r
+#define RUN_AS_USER "bnbt"\r
+\r
+extern map<string, string> gmapCFG;\r
+\r
+void CFG_Open( const char *szFile );\r
+void CFG_SetInt( string strKey, int x );\r
+void CFG_SetString( string strKey, string x );\r
+int CFG_GetInt( string strKey, int x );\r
+string CFG_GetString( string strKey, string x );\r
+void CFG_Delete( string strKey );\r
+void CFG_Close( const char *szFile );\r
+void CFG_SetDefaults( );\r
+\r
+#endif\r
diff --git a/debian/README b/debian/README
new file mode 100644 (file)
index 0000000..261c2af
--- /dev/null
@@ -0,0 +1,6 @@
+The Debian Package bnbt
+----------------------------
+
+Comments regarding the Package
+
+ -- David Bartley <dtbartle@csclub.uwaterloo.ca>  Mon, 25 Jun 2007 06:38:50 -0400
diff --git a/debian/README.Debian b/debian/README.Debian
new file mode 100644 (file)
index 0000000..60d8a4f
--- /dev/null
@@ -0,0 +1,6 @@
+bnbt for Debian
+---------------
+
+<possible notes regarding this package - if none, delete this file>
+
+ -- David Bartley <dtbartle@csclub.uwaterloo.ca>  Mon, 25 Jun 2007 06:38:50 -0400
diff --git a/debian/changelog b/debian/changelog
new file mode 100644 (file)
index 0000000..bc87a18
--- /dev/null
@@ -0,0 +1,5 @@
+bnbt (8.0.10) unstable; urgency=low
+
+  * Initial Release.
+
+ -- David Bartley <dtbartle@csclub.uwaterloo.ca>  Mon, 25 Jun 2007 06:38:50 -0400
diff --git a/debian/compat b/debian/compat
new file mode 100644 (file)
index 0000000..7ed6ff8
--- /dev/null
@@ -0,0 +1 @@
+5
diff --git a/debian/control b/debian/control
new file mode 100644 (file)
index 0000000..ed6de29
--- /dev/null
@@ -0,0 +1,12 @@
+Source: bnbt
+Section: net
+Priority: optional
+Maintainer: David Bartley <dtbartle@csclub.uwaterloo.ca>
+Build-Depends: debhelper (>= 5)
+Standards-Version: 3.7.2
+
+Package: bnbt
+Architecture: any
+Depends: ${shlibs:Depends}, ${misc:Depends}, adduser
+Description: A C++ bittorrent tracker.
+ A C++ bittorrent tracker.
diff --git a/debian/copyright b/debian/copyright
new file mode 100644 (file)
index 0000000..e76f0fe
--- /dev/null
@@ -0,0 +1,26 @@
+This is bnbt, written and maintained by David Bartley <dtbartle@csclub.uwaterloo.ca>
+on Mon, 25 Jun 2007 06:38:50 -0400.
+
+The original source can always be found at:
+       ftp://ftp.debian.org/dists/unstable/main/source/
+
+Copyright Holder:  David Bartley
+
+License:
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  This program is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with this package; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+
+On Debian systems, the complete text of the GNU General
+Public License can be found in `/usr/share/common-licenses/GPL'.
diff --git a/debian/dirs b/debian/dirs
new file mode 100644 (file)
index 0000000..d910ac3
--- /dev/null
@@ -0,0 +1,5 @@
+etc/init.d
+usr/bin
+var/lib/bnbt
+var/lib/bnbt/files
+var/lib/bnbt/torrents
diff --git a/debian/docs b/debian/docs
new file mode 100644 (file)
index 0000000..ea081ad
--- /dev/null
@@ -0,0 +1 @@
+lesser.txt
diff --git a/debian/init.d b/debian/init.d
new file mode 100644 (file)
index 0000000..d07f162
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/sh
+
+PATH=/sbin:/bin:/usr/sbin:/usr/bin
+
+test -x /usr/bin/bnbt || exit 0
+
+start () {
+        echo -n "Starting BitTorrent Tracker: bnbt"
+        start-stop-daemon --start --quiet \
+            --pidfile /var/run/bnbt.pid --exec /usr/bin/bnbt > /dev/null
+        echo "."
+}
+
+stop () {
+        echo -n "Stopping BitTorrent Tracker: bnbt"
+        start-stop-daemon --stop --quiet  \
+            --pidfile /var/run/bnbt.pid --name bnbt
+        echo "."
+}
+
+case "$1" in
+    start)
+        start
+    ;;
+
+    stop)
+        stop
+    ;;
+
+    restart)
+        stop
+        sleep 2
+        start
+    ;;
+    
+    *)
+        echo "Usage: /etc/init.d/bnbt {start|stop|restart}" >&2
+        exit 1
+    ;;
+esac
+
+exit 0
+
diff --git a/debian/postinst b/debian/postinst
new file mode 100644 (file)
index 0000000..8411d05
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+set -e
+
+test "$1" = 'configure' || exit 0
+
+getent passwd bnbt > /dev/null || \
+  adduser --quiet --system --home / --no-create-home bnbt
diff --git a/debian/postrm b/debian/postrm
new file mode 100644 (file)
index 0000000..f0413a6
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+set -e
+
+test "$1" = 'purge' || exit 0
+
+getent passwd bnbt >/dev/null || exit 0
+deluser --quiet --system bnbt
diff --git a/debian/rules b/debian/rules
new file mode 100755 (executable)
index 0000000..2834619
--- /dev/null
@@ -0,0 +1,98 @@
+#!/usr/bin/make -f
+# -*- makefile -*-
+# Sample debian/rules that uses debhelper.
+# This file was originally written by Joey Hess and Craig Small.
+# As a special exception, when this file is copied by dh-make into a
+# dh-make output file, you may use that output file without restriction.
+# This special exception was added by Craig Small in version 0.37 of dh-make.
+
+# Uncomment this to turn on verbose mode.
+#export DH_VERBOSE=1
+
+
+
+
+CFLAGS = -Wall -g
+
+ifneq (,$(findstring noopt,$(DEB_BUILD_OPTIONS)))
+       CFLAGS += -O0
+else
+       CFLAGS += -O2
+endif
+
+configure: configure-stamp
+configure-stamp:
+       dh_testdir
+       # Add here commands to configure the package.
+
+       touch configure-stamp
+
+
+build: build-stamp
+
+build-stamp: configure-stamp 
+       dh_testdir
+
+       # Add here commands to compile the package.
+       $(MAKE)
+       #docbook-to-man debian/bnbt.sgml > bnbt.1
+
+       touch $@
+
+clean:
+       dh_testdir
+       dh_testroot
+       rm -f build-stamp configure-stamp
+
+       # Add here commands to clean up after the build process.
+       -$(MAKE) clean
+
+       dh_clean 
+
+install: build
+       dh_testdir
+       dh_testroot
+       dh_clean -k 
+       dh_installdirs
+
+       # Add here commands to install the package into debian/bnbt.
+       $(MAKE) DESTDIR=$(CURDIR)/debian/bnbt install
+
+
+# Build architecture-independent files here.
+binary-indep: build install
+# We have nothing to do by default.
+
+# Build architecture-dependent files here.
+binary-arch: build install
+       dh_testdir
+       dh_testroot
+       dh_installchangelogs 
+       dh_installdocs
+       dh_installexamples
+#      dh_install
+#      dh_installmenu
+#      dh_installdebconf       
+#      dh_installlogrotate
+#      dh_installemacsen
+#      dh_installpam
+#      dh_installmime
+#      dh_python
+       dh_installinit
+#      dh_installcron
+#      dh_installinfo
+       dh_installman
+       dh_link
+       dh_strip
+       dh_compress
+       dh_fixperms
+#      dh_perl
+#      dh_makeshlibs
+       dh_installdeb
+       dh_shlibdeps
+       dh_gencontrol
+       dh_md5sums
+       dh_builddeb
+
+binary: binary-indep binary-arch
+.PHONY: build clean binary-indep binary-arch binary install configure
diff --git a/footer.html b/footer.html
new file mode 100644 (file)
index 0000000..05ac91f
--- /dev/null
@@ -0,0 +1 @@
+<p>You can change the footer.html file in your tracker's folder to add customized content to your tracker here. You can even change the footer.html file while your tracker is running!</p>\r
diff --git a/header.html b/header.html
new file mode 100644 (file)
index 0000000..2aa8cf2
--- /dev/null
@@ -0,0 +1,3 @@
+<p align=center><a href="/login.html">Login / Your Torrents</a> | <a href="/info.html">Info</a> | <a href="/signup.html">Signup</a> | <a href="/upload.html">Upload A File</a> | <a href="/users.html">Users</a> | <a href="/admin.html">Admin</a></p>\r
+<h2 align=center>My BNBT Tracker</h2>\r
+<p>You can change the header.html file in your tracker's folder to add customized content to your tracker here. You can even change the header.html file while your tracker is running!</p>\r
diff --git a/icon_done.ico b/icon_done.ico
new file mode 100644 (file)
index 0000000..fd11900
Binary files /dev/null and b/icon_done.ico differ
diff --git a/lesser.txt b/lesser.txt
new file mode 100644 (file)
index 0000000..b1e3f5a
--- /dev/null
@@ -0,0 +1,504 @@
+                 GNU LESSER GENERAL PUBLIC LICENSE
+                      Version 2.1, February 1999
+
+ Copyright (C) 1991, 1999 Free Software Foundation, Inc.
+     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+[This is the first released version of the Lesser GPL.  It also counts
+ as the successor of the GNU Library Public License, version 2, hence
+ the version number 2.1.]
+
+                           Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+Licenses are intended to guarantee your freedom to share and change
+free software--to make sure the software is free for all its users.
+
+  This license, the Lesser General Public License, applies to some
+specially designated software packages--typically libraries--of the
+Free Software Foundation and other authors who decide to use it.  You
+can use it too, but we suggest you first think carefully about whether
+this license or the ordinary General Public License is the better
+strategy to use in any particular case, based on the explanations below.
+
+  When we speak of free software, we are referring to freedom of use,
+not price.  Our General Public Licenses are designed to make sure that
+you have the freedom to distribute copies of free software (and charge
+for this service if you wish); that you receive source code or can get
+it if you want it; that you can change the software and use pieces of
+it in new free programs; and that you are informed that you can do
+these things.
+
+  To protect your rights, we need to make restrictions that forbid
+distributors to deny you these rights or to ask you to surrender these
+rights.  These restrictions translate to certain responsibilities for
+you if you distribute copies of the library or if you modify it.
+
+  For example, if you distribute copies of the library, whether gratis
+or for a fee, you must give the recipients all the rights that we gave
+you.  You must make sure that they, too, receive or can get the source
+code.  If you link other code with the library, you must provide
+complete object files to the recipients, so that they can relink them
+with the library after making changes to the library and recompiling
+it.  And you must show them these terms so they know their rights.
+
+  We protect your rights with a two-step method: (1) we copyright the
+library, and (2) we offer you this license, which gives you legal
+permission to copy, distribute and/or modify the library.
+
+  To protect each distributor, we want to make it very clear that
+there is no warranty for the free library.  Also, if the library is
+modified by someone else and passed on, the recipients should know
+that what they have is not the original version, so that the original
+author's reputation will not be affected by problems that might be
+introduced by others.
+\f
+  Finally, software patents pose a constant threat to the existence of
+any free program.  We wish to make sure that a company cannot
+effectively restrict the users of a free program by obtaining a
+restrictive license from a patent holder.  Therefore, we insist that
+any patent license obtained for a version of the library must be
+consistent with the full freedom of use specified in this license.
+
+  Most GNU software, including some libraries, is covered by the
+ordinary GNU General Public License.  This license, the GNU Lesser
+General Public License, applies to certain designated libraries, and
+is quite different from the ordinary General Public License.  We use
+this license for certain libraries in order to permit linking those
+libraries into non-free programs.
+
+  When a program is linked with a library, whether statically or using
+a shared library, the combination of the two is legally speaking a
+combined work, a derivative of the original library.  The ordinary
+General Public License therefore permits such linking only if the
+entire combination fits its criteria of freedom.  The Lesser General
+Public License permits more lax criteria for linking other code with
+the library.
+
+  We call this license the "Lesser" General Public License because it
+does Less to protect the user's freedom than the ordinary General
+Public License.  It also provides other free software developers Less
+of an advantage over competing non-free programs.  These disadvantages
+are the reason we use the ordinary General Public License for many
+libraries.  However, the Lesser license provides advantages in certain
+special circumstances.
+
+  For example, on rare occasions, there may be a special need to
+encourage the widest possible use of a certain library, so that it becomes
+a de-facto standard.  To achieve this, non-free programs must be
+allowed to use the library.  A more frequent case is that a free
+library does the same job as widely used non-free libraries.  In this
+case, there is little to gain by limiting the free library to free
+software only, so we use the Lesser General Public License.
+
+  In other cases, permission to use a particular library in non-free
+programs enables a greater number of people to use a large body of
+free software.  For example, permission to use the GNU C Library in
+non-free programs enables many more people to use the whole GNU
+operating system, as well as its variant, the GNU/Linux operating
+system.
+
+  Although the Lesser General Public License is Less protective of the
+users' freedom, it does ensure that the user of a program that is
+linked with the Library has the freedom and the wherewithal to run
+that program using a modified version of the Library.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.  Pay close attention to the difference between a
+"work based on the library" and a "work that uses the library".  The
+former contains code derived from the library, whereas the latter must
+be combined with the library in order to run.
+\f
+                 GNU LESSER GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License Agreement applies to any software library or other
+program which contains a notice placed by the copyright holder or
+other authorized party saying it may be distributed under the terms of
+this Lesser General Public License (also called "this License").
+Each licensee is addressed as "you".
+
+  A "library" means a collection of software functions and/or data
+prepared so as to be conveniently linked with application programs
+(which use some of those functions and data) to form executables.
+
+  The "Library", below, refers to any such software library or work
+which has been distributed under these terms.  A "work based on the
+Library" means either the Library or any derivative work under
+copyright law: that is to say, a work containing the Library or a
+portion of it, either verbatim or with modifications and/or translated
+straightforwardly into another language.  (Hereinafter, translation is
+included without limitation in the term "modification".)
+
+  "Source code" for a work means the preferred form of the work for
+making modifications to it.  For a library, complete source code means
+all the source code for all modules it contains, plus any associated
+interface definition files, plus the scripts used to control compilation
+and installation of the library.
+
+  Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running a program using the Library is not restricted, and output from
+such a program is covered only if its contents constitute a work based
+on the Library (independent of the use of the Library in a tool for
+writing it).  Whether that is true depends on what the Library does
+and what the program that uses the Library does.
+  
+  1. You may copy and distribute verbatim copies of the Library's
+complete source code as you receive it, in any medium, provided that
+you conspicuously and appropriately publish on each copy an
+appropriate copyright notice and disclaimer of warranty; keep intact
+all the notices that refer to this License and to the absence of any
+warranty; and distribute a copy of this License along with the
+Library.
+
+  You may charge a fee for the physical act of transferring a copy,
+and you may at your option offer warranty protection in exchange for a
+fee.
+\f
+  2. You may modify your copy or copies of the Library or any portion
+of it, thus forming a work based on the Library, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) The modified work must itself be a software library.
+
+    b) You must cause the files modified to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    c) You must cause the whole of the work to be licensed at no
+    charge to all third parties under the terms of this License.
+
+    d) If a facility in the modified Library refers to a function or a
+    table of data to be supplied by an application program that uses
+    the facility, other than as an argument passed when the facility
+    is invoked, then you must make a good faith effort to ensure that,
+    in the event an application does not supply such function or
+    table, the facility still operates, and performs whatever part of
+    its purpose remains meaningful.
+
+    (For example, a function in a library to compute square roots has
+    a purpose that is entirely well-defined independent of the
+    application.  Therefore, Subsection 2d requires that any
+    application-supplied function or table used by this function must
+    be optional: if the application does not supply it, the square
+    root function must still compute square roots.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Library,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Library, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote
+it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Library.
+
+In addition, mere aggregation of another work not based on the Library
+with the Library (or with a work based on the Library) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may opt to apply the terms of the ordinary GNU General Public
+License instead of this License to a given copy of the Library.  To do
+this, you must alter all the notices that refer to this License, so
+that they refer to the ordinary GNU General Public License, version 2,
+instead of to this License.  (If a newer version than version 2 of the
+ordinary GNU General Public License has appeared, then you can specify
+that version instead if you wish.)  Do not make any other change in
+these notices.
+\f
+  Once this change is made in a given copy, it is irreversible for
+that copy, so the ordinary GNU General Public License applies to all
+subsequent copies and derivative works made from that copy.
+
+  This option is useful when you wish to copy part of the code of
+the Library into a program that is not a library.
+
+  4. You may copy and distribute the Library (or a portion or
+derivative of it, under Section 2) in object code or executable form
+under the terms of Sections 1 and 2 above provided that you accompany
+it with the complete corresponding machine-readable source code, which
+must be distributed under the terms of Sections 1 and 2 above on a
+medium customarily used for software interchange.
+
+  If distribution of object code is made by offering access to copy
+from a designated place, then offering equivalent access to copy the
+source code from the same place satisfies the requirement to
+distribute the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  5. A program that contains no derivative of any portion of the
+Library, but is designed to work with the Library by being compiled or
+linked with it, is called a "work that uses the Library".  Such a
+work, in isolation, is not a derivative work of the Library, and
+therefore falls outside the scope of this License.
+
+  However, linking a "work that uses the Library" with the Library
+creates an executable that is a derivative of the Library (because it
+contains portions of the Library), rather than a "work that uses the
+library".  The executable is therefore covered by this License.
+Section 6 states terms for distribution of such executables.
+
+  When a "work that uses the Library" uses material from a header file
+that is part of the Library, the object code for the work may be a
+derivative work of the Library even though the source code is not.
+Whether this is true is especially significant if the work can be
+linked without the Library, or if the work is itself a library.  The
+threshold for this to be true is not precisely defined by law.
+
+  If such an object file uses only numerical parameters, data
+structure layouts and accessors, and small macros and small inline
+functions (ten lines or less in length), then the use of the object
+file is unrestricted, regardless of whether it is legally a derivative
+work.  (Executables containing this object code plus portions of the
+Library will still fall under Section 6.)
+
+  Otherwise, if the work is a derivative of the Library, you may
+distribute the object code for the work under the terms of Section 6.
+Any executables containing that work also fall under Section 6,
+whether or not they are linked directly with the Library itself.
+