summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2011-09-25 04:19:15 -0400
committerAdam <Adam@anope.org>2011-09-25 04:19:15 -0400
commit1f2399de364c09adcce4193895cd362d80ffdfc5 (patch)
tree5f40fc531f22c174b6e10bb7bc12842a4a21d30b /src
parent43201ead9575a74e350710bc191f4ac67366aca7 (diff)
Added a new database format and sqlite support. Also moved db-convert to a module.
Diffstat (limited to 'src')
-rw-r--r--src/access.cpp1
-rw-r--r--src/base.cpp16
-rw-r--r--src/bin/CMakeLists.txt2
-rwxr-xr-xsrc/bin/cp-recursive21
-rwxr-xr-xsrc/bin/langtool239
-rwxr-xr-xsrc/bin/mydbgen148
-rw-r--r--src/bots.cpp23
-rw-r--r--src/hostserv.cpp2
-rw-r--r--src/init.cpp4
-rw-r--r--src/main.cpp1
-rw-r--r--src/memoserv.cpp32
-rw-r--r--src/misc.cpp13
-rw-r--r--src/modes.cpp2
-rw-r--r--src/nickalias.cpp44
-rw-r--r--src/nickcore.cpp51
-rw-r--r--src/operserv.cpp41
-rw-r--r--src/regchannel.cpp221
-rw-r--r--src/tools/db-convert.cpp1032
-rw-r--r--src/tools/db-convert.h975
19 files changed, 438 insertions, 2430 deletions
diff --git a/src/access.cpp b/src/access.cpp
index 8a293a42d..d519abf39 100644
--- a/src/access.cpp
+++ b/src/access.cpp
@@ -11,7 +11,6 @@
#include "services.h"
#include "modules.h"
-#include "access.h"
enum
{
diff --git a/src/base.cpp b/src/base.cpp
index 0aec072a1..18450ef90 100644
--- a/src/base.cpp
+++ b/src/base.cpp
@@ -1,6 +1,22 @@
#include "services.h"
#include "modules.h"
+std::vector<SerializableBase *> serialized_types;
+std::list<SerializableBase *> serialized_items;
+
+void RegisterTypes()
+{
+ Serializable<NickCore>::Alloc.Register("NickCore");
+ Serializable<NickAlias>::Alloc.Register("NickAlias");
+ Serializable<BotInfo>::Alloc.Register("BotInfo");
+ Serializable<ChannelInfo>::Alloc.Register("ChannelInfo");
+ Serializable<LogSetting>::Alloc.Register("LogSetting");
+ Serializable<ModeLock>::Alloc.Register("ModeLock");
+ Serializable<AutoKick>::Alloc.Register("AutoKick");
+ Serializable<BadWord>::Alloc.Register("BadWord");
+ Serializable<Memo>::Alloc.Register("Memo");
+}
+
Base::Base()
{
}
diff --git a/src/bin/CMakeLists.txt b/src/bin/CMakeLists.txt
index 7c6fe514b..cb110edb5 100644
--- a/src/bin/CMakeLists.txt
+++ b/src/bin/CMakeLists.txt
@@ -1,7 +1,7 @@
# If not on Windows, generate anoperc and install it along with mydbgen
if(NOT WIN32)
configure_file(${Anope_SOURCE_DIR}/src/bin/anoperc.in ${Anope_BINARY_DIR}/src/bin/anoperc)
- install (PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/anoperc ${CMAKE_CURRENT_SOURCE_DIR}/mydbgen
+ install (PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/anoperc
DESTINATION bin
)
diff --git a/src/bin/cp-recursive b/src/bin/cp-recursive
deleted file mode 100755
index e51230db7..000000000
--- a/src/bin/cp-recursive
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/bin/sh
-
-if [ $1 = "-t" ] ; then
- shift
-fi
-if [ ! "$2" ] ; then
- echo >&2 Usage: $0 '<sourcedir> <targetdir>'
- exit 1
-fi
-if [ -d "$1" ] ; then
- dir="$1"
-else
- dir="`echo $1 | sed 's#\(.*\)/.*#\1#'`"
-fi
-while [ "$2" ] ; do
- shift
-done
-if [ ! -d $1 ] ; then
- mkdir -p $1 || exit 1
-fi
-/bin/tar -Ccf $dir - . | /bin/tar -Cxf $1 -
diff --git a/src/bin/langtool b/src/bin/langtool
deleted file mode 100755
index c1072760c..000000000
--- a/src/bin/langtool
+++ /dev/null
@@ -1,239 +0,0 @@
-#!/usr/bin/perl
-#
-# Ribosome's all in one language tool
-# 1) Compares to check for missing lines
-# 2) Compares to check for equal lines
-# 3) Fixes (on request) missing lines
-# 4) Checks for errors in lines
-# 5) Checks for long lines (>60 characters)
-#
-
-# Check to see if we have received arguments
-if (!$ARGV[0]) {
-print "Usage: $0 [language file]\n";
-exit;
-}
-
-# If yes, set $sourcefile to the language filename
-$testagainst = $ARGV[0];
-
-# Set $sourcefile to en_us language file
-$sourcefile = "en_us.l";
-
-# Number of Keys in File, Number of Equal Lines, Number of Missing Lines
-# Fixed Lines (optional) and Number of Format Error Lines, Number of Long Lines
-my $numberlines = 0;
-my $equallines = 0;
-my $missinglines = 0;
-my $fixedlines = 0;
-my $errorline = 0;
-my $longlines = 0;
-
-# Array to hold the lines from the source file and explosion array for long line check
-
-my @sourcearray;
-my @explosion;
-
-# Create associative arrays which will contain keys and definitions
-# One for the control source and one for what is being tested against
-
-my %sourcehash= ();
-my %testhash= ();
-
-# Check if Files Exist
-
-if (! -f $sourcefile) {
-print "Critical Error: The source file does not exist or is unreadable.\nNote: This tool must be run from the language directory.\n";
-exit;
-}
-
-if (! -f $testagainst) {
-print "Critical Error: The language file does not exist or is unreadable\n";
-exit;
-}
-###########################################
-# Function to load sourcefile into memory #
-###########################################
-
-sub load_sourcefile {
-
- my $_key; # This variable will hold the key
- my $_def; # This variable will hold the definition
- my $line; # This variable will hold the current line
-
- open (SOURCEFILE, "< $sourcefile"); # Open the source file
- while (<SOURCEFILE>) { # For each line the source file
- $line = $_; # $line is set to the line in the source file
-
- # Skip comments
- if (/^#/) { # This checks for # which indicates comment
- next; # If detected, the next line is skipped to
- }
-
- # Start of a key
- if (/^[A-Z]/) { # Checks to see if the line is a key
- chomp($line); # Removes things that shouldn't be at the end
- push (@sourcearray, $line); # Puts the line into the source array
- # If a key is defined, load definition into the hash
- if ($_key ne undef) { # If the key is defined
- $sourcehash{$_key} = $_def; # Add the definition to the associative array
- }
- $_key=$line; # Set the key to the line
- $_def=""; # Reset the definition
- next; # Move onto the next line
- }
-
- if ($_key ne undef) { # If the key is set already
- $_def.=$line; # The definition is the current line
- }
-
- $sourcehash{$_key} = $_def; # Load the definition into the associative array
- } # End of while which reads lines
-
- close (SOURCEFILE); # Close the source file
-
-} # End of load_sourcefile function
-
-#################################################
-# Function to load testagainst file into memory #
-#################################################
-
-sub load_testagainst {
-
- my $_key; # This variable will hold the key
- my $_def; # This variable will hold the definition
- my $line; # This variable will hold the current line
-
- open (TESTAGAINSTFILE, "< $testagainst"); # Open the file containing the control lines
- while (<TESTAGAINSTFILE>) { # For each line in the file
- $line = $_; # $line is set to the lines value
-
-
- # Skip comments
- if (/^#/) { # This checks for # which indicates comment
- next; # If detected, the next line is skipped to
- }
-
- # Start of a key
- if (/^[A-Z]/) { # Checks to see if the line is a key
- chomp($line); # Removes things that shouldn't be at the end
-
-
- if ($_key ne undef) { # If the key is defined
- $testhash{$_key} = $_def; # Add the definition to the associative array
- }
- $_key=$line; # Set the key to the line
- $_def=""; # Reset the definition
- next; # Move onto the next line
- }
-
- if ($_key ne undef) { # If the key is set already
- $_def.=$line; # The definition is the current line
- }
-
- $testhash{$_key} = $_def; # Load the definition into the associative array
- } # End of while which reads lines
- close (TESTAGAINSTFILE); # Close the source file
-
-}
-
-
-sub get_format { # Function to get the formatting from a string
- my $fmt="";
- my $str=shift; # Get the input
-
- while ($str =~ m/%\w/g) {
- $fmt .= $&;
- }
-
- return $fmt; # Return the formatting
-}
-
-
-load_sourcefile; # Call function to load the source file
-load_testagainst; # Call function to load the test file
-
-if (!grep(/^LANG_NAME/,%testhash)) {
-print "Critical Error: $ARGV[0] is not a valid language file!\n";
-exit;
-}
-
-open (LOG,"> langcheck.log"); # Open logfile for writing
-
-foreach $sourcearray (@sourcearray) { # For each key stored in the source array
- my $_key=$_; # Store key from source array in $_key
-
- if ((get_format($sourcehash{$sourcearray})) ne (get_format($testhash{$sourcearray}))) {
- if ($sourcearray !~ STRFTIME ) {
- $errorline++;
- print LOG "FORMAT: $sourcearray - (expecting '".get_format($sourcehash{$sourcearray})."' and got '".get_format($testhash{$sourcearray})."')\n";
- } }
-
- if ($testhash{$sourcearray} eq $sourcehash{$sourcearray} ) {
- # If the definitions between the source and the test are equal
- $equallines++; # Number of equal lines increases
- print LOG "EQUAL: $sourcearray\n"; # Line is written to logfile
- }
-
- if (!grep(/^$sourcearray/,%testhash)) { # If the key is found in the testhash associative array
- $missinglines++; # Increase missing lines
- print LOG "MISSING: $sourcearray\n"; # Line is written to logfile
- }
-
- @explosion = split(/\n/, $testhash{$sourcearray});
- foreach $explosion (@explosion) {
- $explosion =~ s/\002//g;
- $explosion =~ s/\037//g;
- if (length($explosion) > 61) {
- print LOG "LONGLINE: $sourcearray (".substr($explosion,1,30)."...)\n";
- $longlines++;
- }
- }
-
-$numberlines++; # Increase the number of lines tested by 1
-}
-close (LOG); # Close the logfile
-
-
-#########################
-# Show the test results #
-#########################
-
-print "Calculation Results:\n";
-print "----------------------------------\n";
-print "[$numberlines] line(s) were compared\n";
-print "[$equallines] line(s) were found to equal their $sourcefile counterpart(s)\n";
-print "[$missinglines] line(s) were found to be missing\n";
-print "[$longlines] line(s) were found to be long (>60 chars)\n";
-print "[$errorline] line(s) were found to have formatting errors\n";
-print "The specific details of the test have been saved in langcheck.log\n";
-
-if ($missinglines) { # If missing lines exist
-print "----------------------------------\n";
-print "Missing line(s) have been detected in this test, would you like to fix the file?\n";
-print "This automatically inserts values from the control file ($sourcefile) for the missing values\n";
-print "y/N? (Default: No) ";
-
-my $input = <STDIN>; # Ask if the file should be fixed
-if ((substr($input,0,1) eq "y") || (substr($input,0,1) eq "Y")) { # If Yes...
-
-open (FIX, ">> $testagainst"); # Open the file and append changes
-
-foreach $sourcearray (@sourcearray) { # For each key stored in the source array
- my $_key=$_; # Store key from source array in $_key
-
- if (!grep(/^$sourcearray/,%testhash)) { # If the key is not found in the testhash associative array
- print FIX "$sourcearray\n$sourcehash{$sourcearray}"; # Add the line(s) to the language file
- $fixedlines++; # Increase the fixed line count
- }
-}
-
-close (FIX); # Close file after fixing
-
-print "Fixing Compete. [$fixedlines] line(s) fixed.\n";
-exit; # And Exit!
-}
- # Otherwise, quit without fixing
-print "Exiting. The language file has NOT been fixed.\n";
-
-}
diff --git a/src/bin/mydbgen b/src/bin/mydbgen
deleted file mode 100755
index 12bee8063..000000000
--- a/src/bin/mydbgen
+++ /dev/null
@@ -1,148 +0,0 @@
-#!/bin/sh
-#
-
-# Location of the .sql file with the schema
-DBSQL="tables.sql"
-
-# Schema Version
-SVER="2"
-
-# Local Version, defaults to 0
-LVER="0"
-
-TFILE="/tmp/.anopedb.$$"
-
-if [ "`eval echo -n 'a'`" = "-n a" ] ; then
- c="\c"
-else
- n="-n"
-fi
-
-DBFILE=../data/$DBSQL
-
-if [ ! -f "./$DBFILE" ] ; then
- echo "Error: Required file $DBSQL was not found!";
- exit
-fi
-
-echo ""
-echo "This script will guide you through the process of configuring your Anope"
-echo "installation to make use of MySQL support. This script must be used for both"
-echo "new installs as well as for upgrading for users who have a previous version"
-echo "of Anope installed"
-
-while [ -z "$SQLHOST" ] ; do
- echo ""
- echo "What is the hostname of your MySQL server?"
- echo $n "-> $c"
- read cc
- if [ ! -z "$cc" ] ; then
- SQLHOST=$cc
- fi
-done
-
-while [ -z "$SQLUSER" ] ; do
- echo ""
- echo "What is your MySQL username?"
- echo $n "-> $c"
- read cc
- if [ ! -z "$cc" ] ; then
- SQLUSER=$cc
- fi
-done
-
-OLD_TTY=`stty -g`
-
-echo ""
-echo "What is your MySQL password?"
-echo $n "-> $c"
-stty -echo echonl
-read cc
-SQLPASS_PREFIX=""
-if [ ! -z "$cc" ] ; then
- SQLPASS_PREFIX="-p"
- SQLPASS=$cc
-fi
-stty $OLD_TTY
-
-mysqlshow -h$SQLHOST -u$SQLUSER $SQLPASS_PREFIX$SQLPASS >/dev/null 2>&1
-if test "$?" = "1" ; then
- echo "Error: Unable to login, verify your login/password and hostname"
- exit
-fi
-
-while [ -z "$SQLDB" ] ; do
- echo ""
- echo "What is the name of the Anope SQL database?"
- echo $n "-> $c"
- read cc
- if [ ! -z "$cc" ] ; then
- SQLDB=$cc
- fi
-done
-
-MYSQLDUMP="mysqldump -h$SQLHOST -u$SQLUSER $SQLPASS_PREFIX$SQLPASS $SQLDB"
-MYSQLSHOW="mysqlshow -h$SQLHOST -u$SQLUSER $SQLPASS_PREFIX$SQLPASS $SQLDB"
-MYSQL="mysql -h$SQLHOST -u$SQLUSER $SQLPASS_PREFIX$SQLPASS $SQLDB"
-
-echo ""
-
-$MYSQLSHOW | grep -q $SQLDB
-if test "$?" = "1" ; then
- echo -n "Unable to find databse, creating... "
- mysql -h$SQLHOST -u$SQLUSER $SQLPASS_PREFIX$SQLPASS -Bs -e "create database $SQLDB" >/dev/null 2>&1
- if test "$?" = "0" ; then
- echo "done!"
- else
- echo "failed!"
- FAILED="$FAILED 'database creation'"
- fi
-fi
-
-$MYSQL -Bs -e "show tables like 'anope_os_core'" | grep -q anope_os_core
-if test "$?" = "1" ; then
- echo -n "Unable to find Anope schema, creating... "
- $MYSQL < $DBFILE
- if test "$?" = "0" ; then
- echo "done!"
- else
- echo "failed!"
- FAILED="$FAILED 'schema creation'"
- fi
-else
- echo "done!"
-fi
-
-echo ""
-
-if [ $LVER -ne $SVER ]; then
-echo -n "Inserting initial version number... "
-$MYSQL -Bs -e "delete from anope_info"
-echo "INSERT INTO anope_info (version, date) VALUES ($SVER, now())" > $TFILE
-$MYSQL < $TFILE >/dev/null 2>&1
-if test "$?" = "0" ; then
- echo "done!"
-else
- echo "failed!"
- FAILED="$FAILED 'version insert'"
-fi
-fi
-
-rm -f $TFILE
-if test "x$FAILED" = "x" ; then
- # Try to find out more about this installation
- SQLPORT="$(mysql_config --port 2> /dev/null)"
- if test "$SQLPORT" = "0" ; then
- SQLPORT=3306
- fi
- echo ""
- echo "Your MySQL setup is complete and your Anope schema is up to date. Make"
- echo "sure you configure MySQL on your services.conf file prior to launching"
- echo "Anope with MySQL support."
- echo ""
-else
- echo "The following operations failed:"
- echo "$FAILED"
-fi
-
-exit
diff --git a/src/bots.cpp b/src/bots.cpp
index 390fc6a69..928dcb2c1 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -64,6 +64,29 @@ BotInfo::~BotInfo()
BotListByUID.erase(this->uid);
}
+SerializableBase::serialized_data BotInfo::serialize()
+{
+ SerializableBase::serialized_data data;
+
+ data["nick"] << this->nick;
+ data["user"] << this->ident;
+ data["host"] << this->host;
+ data["realname"] << this->realname;
+ data["created"] << this->created;
+ data["chancount"] << this->chancount;
+
+ return data;
+}
+
+void BotInfo::unserialize(SerializableBase::serialized_data &data)
+{
+ BotInfo *bi = findbot(data["nick"].astr());
+ if (bi == NULL)
+ bi = new BotInfo(data["nick"].astr(), data["user"].astr(), data["host"].astr(), data["realname"].astr());
+ data["created"] >> bi->created;
+ data["chancount"] >> bi->chancount;
+}
+
void BotInfo::GenerateUID()
{
if (!this->uid.empty())
diff --git a/src/hostserv.cpp b/src/hostserv.cpp
index d3000d552..55cbaff29 100644
--- a/src/hostserv.cpp
+++ b/src/hostserv.cpp
@@ -72,7 +72,7 @@ const Anope::string &HostInfo::GetCreator() const
/** Retrieve when the vhost was crated
* @return the time it was created
*/
-const time_t HostInfo::GetTime() const
+time_t HostInfo::GetTime() const
{
return Time;
}
diff --git a/src/init.cpp b/src/init.cpp
index beb34aafb..c4cd62b07 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -241,6 +241,8 @@ void Init(int ac, char **av)
#endif
if (set_group() < 0)
throw FatalException("set_group() fail");
+
+ RegisterTypes();
/* Parse command line arguments */
ParseCommandLineArguments(ac, av);
@@ -442,8 +444,6 @@ void Init(int ac, char **av)
EventReturn MOD_RESULT;
FOREACH_RESULT(I_OnLoadDatabase, OnLoadDatabase());
Log() << "Databases loaded";
-
- FOREACH_MOD(I_OnPostLoadDatabases, OnPostLoadDatabases());
}
/*************************************************************************/
diff --git a/src/main.cpp b/src/main.cpp
index aab9edce5..5d3b5e3de 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -375,6 +375,7 @@ int main(int ac, char **av, char **envp)
ModuleManager::UnloadModule(m, NULL);
ModuleManager::CleanupRuntimeDirectory();
+ serialized_items.clear();
#ifdef _WIN32
OnShutdown();
diff --git a/src/memoserv.cpp b/src/memoserv.cpp
index 21940aca1..faaca180b 100644
--- a/src/memoserv.cpp
+++ b/src/memoserv.cpp
@@ -11,9 +11,41 @@
#include "services.h"
#include "modules.h"
+#include "memoserv.h"
Memo::Memo() : Flags<MemoFlag>(MemoFlagStrings) { }
+SerializableBase::serialized_data Memo::serialize()
+{
+ serialized_data data;
+
+ data["owner"] << this->owner;
+ data["time"] << this->time;
+ data["sender"] << this->sender;
+ data["text"] << this->text;
+
+ return data;
+}
+
+void Memo::unserialize(SerializableBase::serialized_data &data)
+{
+ if (!memoserv)
+ return;
+
+ bool ischan;
+ MemoInfo *mi = memoserv->GetMemoInfo(data["owner"].astr(), ischan);
+ if (!mi)
+ return;
+
+ Memo *m = new Memo();
+ data["owner"] >> m->owner;
+ data["time"] >> m->time;
+ data["sender"] >> m->sender;
+ data["text"] >> m->text;
+
+ mi->memos.push_back(m);
+}
+
unsigned MemoInfo::GetIndex(Memo *m) const
{
for (unsigned i = 0; i < this->memos.size(); ++i)
diff --git a/src/misc.cpp b/src/misc.cpp
index 5e41d42b7..0090dfa3b 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -14,6 +14,19 @@
#include "version.h"
#include "modules.h"
+ExtensibleItem::ExtensibleItem()
+{
+}
+
+ExtensibleItem::~ExtensibleItem()
+{
+}
+
+void ExtensibleItem::OnDelete()
+{
+ delete this;
+}
+
struct arc4_stream
{
uint8 i;
diff --git a/src/modes.cpp b/src/modes.cpp
index 4fc5d6483..e6f3a27a1 100644
--- a/src/modes.cpp
+++ b/src/modes.cpp
@@ -54,7 +54,7 @@ void SetDefaultMLock(ServerConfig *config)
if (cm->Type != MODE_LIST) // Only MODE_LIST can have duplicates
def_mode_locks.erase(cm->Name);
- def_mode_locks.insert(std::make_pair(cm->Name, ModeLock(adding == 1, cm->Name, param)));
+ def_mode_locks.insert(std::make_pair(cm->Name, ModeLock(NULL, adding == 1, cm->Name, param)));
}
}
}
diff --git a/src/nickalias.cpp b/src/nickalias.cpp
index f5269cc9f..7b07a4af3 100644
--- a/src/nickalias.cpp
+++ b/src/nickalias.cpp
@@ -102,3 +102,47 @@ void NickAlias::OnCancel(User *)
new NickServRelease(this, Config->NSReleaseTimeout);
}
}
+
+SerializableBase::serialized_data NickAlias::serialize()
+{
+ serialized_data data;
+
+ data["nick"].setKey().setMax(Config->NickLen) << this->nick;
+ data["last_quit"] << this->last_quit;
+ data["last_realname"] << this->last_realname;
+ data["last_usermask"] << this->last_usermask;
+ data["last_realhost"] << this->last_realhost;
+ data["time_registered"].setType(Serialize::DT_INT) << this->time_registered;
+ data["last_seen"].setType(Serialize::DT_INT) << this->last_seen;
+ data["nc"] << this->nc->display;
+
+ if (this->hostinfo.HasVhost())
+ {
+ data["vhost_ident"] << this->hostinfo.GetIdent();
+ data["vhost_host"] << this->hostinfo.GetHost();
+ data["vhost_creator"] << this->hostinfo.GetCreator();
+ data["vhost_time"] << this->hostinfo.GetTime();
+ }
+
+ return data;
+}
+
+void NickAlias::unserialize(SerializableBase::serialized_data &data)
+{
+ NickCore *core = findcore(data["nc"].astr());
+ if (core == NULL)
+ return;
+
+ NickAlias *na = new NickAlias(data["nick"].astr(), core);
+ data["last_quit"] >> na->last_quit;
+ data["last_realname"] >> na->last_realname;
+ data["last_usermask"] >> na->last_usermask;
+ data["last_realhost"] >> na->last_realhost;
+ data["time_registered"] >> na->time_registered;
+ data["last_seen"] >> na->last_seen;
+
+ time_t vhost_time;
+ data["vhost_time"] >> vhost_time;
+ na->hostinfo.SetVhost(data["vhost_ident"].astr(), data["vhost_host"].astr(), data["vhost_creator"].astr(), vhost_time);
+}
+
diff --git a/src/nickcore.cpp b/src/nickcore.cpp
index a33382f06..968e4d0e9 100644
--- a/src/nickcore.cpp
+++ b/src/nickcore.cpp
@@ -45,6 +45,57 @@ NickCore::~NickCore()
}
}
+SerializableBase::serialized_data NickCore::serialize()
+{
+ serialized_data data;
+
+ data["display"].setKey().setMax(Config->NickLen) << this->display;
+ data["pass"] << this->pass;
+ data["email"] << this->email;
+ data["greet"] << this->greet;
+ data["language"] << this->language;
+ for (unsigned i = 0; i < this->access.size(); ++i)
+ data["access"] << this->access[i] << " ";
+ for (unsigned i = 0; i < this->cert.size(); ++i)
+ data["cert"] << this->cert[i] << " ";
+ data["memomax"] << this->memos.memomax;
+ for (unsigned i = 0; i < this->memos.ignores.size(); ++i)
+ data["memoignores"] << this->memos.ignores[i] << " ";
+
+ return data;
+}
+
+void NickCore::unserialize(serialized_data &data)
+{
+ NickCore *nc = new NickCore(data["display"].astr());
+ data["pass"] >> nc->pass;
+ data["email"] >> nc->email;
+ data["greet"] >> nc->greet;
+ data["language"] >> nc->language;
+ {
+ Anope::string buf;
+ data["access"] >> buf;
+ spacesepstream sep(buf);
+ while (sep.GetToken(buf))
+ nc->access.push_back(buf);
+ }
+ {
+ Anope::string buf;
+ data["cert"] >> buf;
+ spacesepstream sep(buf);
+ while (sep.GetToken(buf))
+ nc->access.push_back(buf);
+ }
+ data["memomax"] >> nc->memos.memomax;
+ {
+ Anope::string buf;
+ data["memoignores"] >> buf;
+ spacesepstream sep(buf);
+ while (sep.GetToken(buf))
+ nc->memos.ignores.push_back(buf);
+ }
+}
+
bool NickCore::IsServicesOper() const
{
return this->o != NULL;
diff --git a/src/operserv.cpp b/src/operserv.cpp
index b17f9e0ad..b0db3aee1 100644
--- a/src/operserv.cpp
+++ b/src/operserv.cpp
@@ -16,6 +16,10 @@
/* List of XLine managers we check users against in XLineManager::CheckAll */
std::list<XLineManager *> XLineManager::XLineManagers;
+XLine::XLine()
+{
+}
+
XLine::XLine(const Anope::string &mask, const Anope::string &reason) : Mask(mask), Created(0), Expires(0), Reason(reason)
{
}
@@ -66,6 +70,37 @@ sockaddrs XLine::GetIP() const
return addr;
}
+SerializableBase::serialized_data XLine::serialize()
+{
+ serialized_data data;
+
+ data["mask"] << this->Mask;
+ data["by"] << this->By;
+ data["created"] << this->Created;
+ data["expires"] << this->Expires;
+ data["reason"] << this->Reason;
+ data["manager"] << this->Manager;
+
+ return data;
+}
+
+void XLine::unserialize(SerializableBase::serialized_data &data)
+{
+ service_reference<XLineManager> xlm(data["manager"].astr());
+ if (!xlm)
+ return;
+
+ XLine *xl = new XLine();
+
+ data["mask"] >> xl->Mask;
+ data["by"] >> xl->By;
+ data["created"] >> xl->Created;
+ data["expires"] >> xl->Expires;
+ data["reason"] >> xl->Reason;
+
+ xlm->AddXLine(xl);
+}
+
/** Constructor
*/
XLineManager::XLineManager(Module *creator, const Anope::string &xname, char t) : Service<XLineManager>(creator, xname), type(t)
@@ -159,6 +194,7 @@ const std::vector<XLine *> &XLineManager::GetList() const
*/
void XLineManager::AddXLine(XLine *x)
{
+ x->Manager = this->name;
this->XLines.push_back(x);
}
@@ -199,8 +235,9 @@ XLine *XLineManager::GetEntry(unsigned index)
*/
void XLineManager::Clear()
{
- while (!this->XLines.empty())
- this->DelXLine(this->XLines.front());
+ for (unsigned i = 0; i < this->XLines.size(); ++i)
+ delete this->XLines[i];
+ this->XLines.clear();
}
/** Add an entry to this XLine Manager
diff --git a/src/regchannel.cpp b/src/regchannel.cpp
index 7eceb5942..4c90fa458 100644
--- a/src/regchannel.cpp
+++ b/src/regchannel.cpp
@@ -12,6 +12,124 @@
#include "services.h"
#include "modules.h"
+SerializableBase::serialized_data BadWord::serialize()
+{
+ serialized_data data;
+
+ data["word"] << this->word;
+ data["type"].setType(Serialize::DT_INT) << this->type;
+
+ return data;
+}
+
+void BadWord::unserialize(SerializableBase::serialized_data &data)
+{
+ BadWord *bw = new BadWord();
+ data["word"] >> bw->word;
+ unsigned int n;
+ data["type"] >> n;
+ bw->type = static_cast<BadWordType>(n);
+}
+
+SerializableBase::serialized_data AutoKick::serialize()
+{
+ serialized_data data;
+
+ if (this->HasFlag(AK_ISNICK) && this->nc)
+ data["nc"] << this->nc->display;
+ else
+ data["mask"] << this->mask;
+ data["reason"] << this->reason;
+ data["creator"] << this->creator;
+ data["addtime"].setType(Serialize::DT_INT) << this->addtime;
+ data["last_used"].setType(Serialize::DT_INT) << this->last_used;
+
+ return data;
+}
+
+void AutoKick::unserialize(SerializableBase::serialized_data &data)
+{
+ AutoKick *ak = new AutoKick();
+
+ data["mask"] >> ak->mask;
+ ak->nc = findcore(data["nc"].astr());
+ data["reason"] >> ak->reason;
+ data["creator"] >> ak->creator;
+ data["addtime"] >> ak->addtime;
+ data["last_used"] >> ak->last_used;
+}
+
+SerializableBase::serialized_data ModeLock::serialize()
+{
+ serialized_data data;
+
+ if (this->ci == NULL)
+ return data;
+
+ data["ci"] << this->ci->name;
+ data["set"] << this->set;
+ data["name"] << ChannelModeNameStrings[this->name];
+ data["param"] << this->param;
+ data["setter"] << this->setter;
+ data["created"].setType(Serialize::DT_INT) << this->created;
+
+ return data;
+}
+
+void ModeLock::unserialize(SerializableBase::serialized_data &data)
+{
+ ChannelInfo *ci = cs_findchan(data["ci"].astr());
+ if (ci == NULL)
+ return;
+
+ ModeLock ml;
+
+ ml.ci = ci;
+
+ data["set"] >> ml.set;
+ Anope::string n;
+ data["name"] >> n;
+ for (unsigned i = 0; !ChannelModeNameStrings[i].empty(); ++i)
+ if (n == ChannelModeNameStrings[i])
+ {
+ ml.name = static_cast<ChannelModeName>(i);
+ break;
+ }
+ data["param"] >> ml.param;
+ data["setter"] >> ml.setter;
+ data["created"] >> ml.created;
+
+ ci->mode_locks.insert(std::make_pair(ml.name, ml));
+}
+
+SerializableBase::serialized_data LogSetting::serialize()
+{
+ serialized_data data;
+
+ data["service_name"] << service_name;
+ data["command_service"] << command_service;
+ data["command_name"] << command_name;
+ data["method"] << method;
+ data["extra"] << extra;
+ data["creator"] << creator;
+ data["created"].setType(Serialize::DT_INT) << created;
+
+ return data;
+}
+
+void LogSetting::unserialize(serialized_data &data)
+{
+ LogSetting ls;
+
+ data["service_name"] >> ls.service_name;
+ data["command_service"] >> ls.command_service;
+ data["command_name"] >> ls.command_name;
+ data["method"] >> ls.method;
+ data["extra"] >> ls.extra;
+ data["creator"] >> ls.creator;
+ data["created"] >> ls.created;
+}
+
/** Default constructor
* @param chname The channel name
*/
@@ -142,6 +260,83 @@ ChannelInfo::~ChannelInfo()
--this->founder->channelcount;
}
+SerializableBase::serialized_data ChannelInfo::serialize()
+{
+ serialized_data data;
+
+ data["name"].setKey().setMax(255) << this->name;
+ if (this->founder)
+ data["founder"] << this->founder->display;
+ if (this->successor)
+ data["successor"] << this->successor->display;
+ data["description"] << this->desc;
+ data["time_registered"].setType(Serialize::DT_INT) << this->time_registered;
+ data["last_used"].setType(Serialize::DT_INT) << this->last_used;
+ data["last_topic"] << this->last_topic;
+ data["last_topic_setter"] << this->last_topic_setter;
+ data["last_topic_time"].setType(Serialize::DT_INT) << this->last_topic_time;
+ data["bantype"].setType(Serialize::DT_INT) << this->bantype;
+ data["botflags"] << this->botflags.ToString();
+ {
+ Anope::string levels_buffer;
+ for (std::map<Anope::string, int16>::iterator it = this->levels.begin(), it_end = this->levels.end(); it != it_end; ++it)
+ levels_buffer += it->first + " " + stringify(it->second) + " ";
+ data["levels"] << levels_buffer;
+ }
+ if (this->bi)
+ data["bi"] << this->bi->nick;
+ for (int i = 0; i < TTB_SIZE; ++i)
+ data["ttb"] << this->ttb[i] << " ";
+ data["capsmin"].setType(Serialize::DT_INT) << this->capsmin;
+ data["capspercent"].setType(Serialize::DT_INT) << this->capspercent;
+ data["floodlines"].setType(Serialize::DT_INT) << this->floodlines;
+ data["floodsecs"].setType(Serialize::DT_INT) << this->floodsecs;
+ data["repeattimes"].setType(Serialize::DT_INT) << this->repeattimes;
+ data["memomax"] << this->memos.memomax;
+ for (unsigned i = 0; i < this->memos.ignores.size(); ++i)
+ data["memoignores"] << this->memos.ignores[i] << " ";
+
+ return data;
+}
+
+void ChannelInfo::unserialize(SerializableBase::serialized_data &data)
+{
+ ChannelInfo *ci = new ChannelInfo(data["name"].astr());
+ if (data.count("founder") > 0)
+ ci->founder = findcore(data["founder"].astr());
+ if (data.count("successor") > 0)
+ ci->successor = findcore(data["successor"].astr());
+ data["description"] >> ci->desc;
+ data["time_registered"] >> ci->time_registered;
+ data["last_used"] >> ci->last_used;
+ data["last_topic"] >> ci->last_topic;
+ data["last_topic_setter"] >> ci->last_topic_setter;
+ data["last_topic_time"] >> ci->last_topic_time;
+ data["bantype"] >> ci->bantype;
+ ci->botflags.FromString(data["botflags"].astr());
+ {
+ std::vector<Anope::string> v = BuildStringVector(data["levels"].astr());
+ for (unsigned i = 0; i + 1 < v.size(); i += 2)
+ ci->levels[v[i]] = convertTo<int16>(v[i + 1]);
+ }
+ if (data.count("bi") > 0)
+ ci->bi = findbot(data["bi"].astr());
+ data["capsmin"] >> ci->capsmin;
+ data["capspercent"] >> ci->capspercent;
+ data["floodlines"] >> ci->floodlines;
+ data["floodsecs"] >> ci->floodsecs;
+ data["repeattimes"] >> ci->repeattimes;
+ data["memomax"] >> ci->memos.memomax;
+ {
+ Anope::string buf;
+ data["memoignores"] >> buf;
+ spacesepstream sep(buf);
+ while (sep.GetToken(buf))
+ ci->memos.ignores.push_back(buf);
+ }
+}
+
+
/** Change the founder of the channek
* @params nc The new founder
*/
@@ -338,6 +533,7 @@ AutoKick *ChannelInfo::AddAkick(const Anope::string &user, const Anope::string &
{
AutoKick *autokick = new AutoKick();
autokick->mask = mask;
+ autokick->nc = NULL;
autokick->reason = reason;
autokick->creator = user;
autokick->addtime = t;
@@ -484,7 +680,7 @@ bool ChannelInfo::SetMLock(ChannelMode *mode, bool status, const Anope::string &
{
if (setter.empty())
setter = this->founder ? this->founder->display : "Unknown";
- std::pair<ChannelModeName, ModeLock> ml = std::make_pair(mode->Name, ModeLock(status, mode->Name, param, setter, created));
+ std::pair<ChannelModeName, ModeLock> ml = std::make_pair(mode->Name, ModeLock(this, status, mode->Name, param, setter, created));
EventReturn MOD_RESULT;
FOREACH_RESULT(I_OnMLock, OnMLock(this, &ml.second));
@@ -525,13 +721,20 @@ bool ChannelInfo::SetMLock(ChannelMode *mode, bool status, const Anope::string &
*/
bool ChannelInfo::RemoveMLock(ChannelMode *mode, const Anope::string &param)
{
- EventReturn MOD_RESULT;
- FOREACH_RESULT(I_OnUnMLock, OnUnMLock(this, mode, param));
- if (MOD_RESULT == EVENT_STOP)
- return false;
-
if (mode->Type == MODE_REGULAR || mode->Type == MODE_PARAM)
- return this->mode_locks.erase(mode->Name) > 0;
+ {
+ std::multimap<ChannelModeName, ModeLock>::iterator it = this->mode_locks.find(mode->Name), it_end = this->mode_locks.upper_bound(mode->Name), it_next = it;
+ if (it != this->mode_locks.end())
+ for (; it != it_end; it = it_next)
+ {
+ ++it_next;
+ EventReturn MOD_RESULT;
+ FOREACH_RESULT(I_OnUnMLock, OnUnMLock(this, &it->second));
+ if (MOD_RESULT != EVENT_STOP)
+ this->mode_locks.erase(it);
+ }
+ return true;
+ }
else
{
// For list or status modes, we must check the parameter
@@ -544,6 +747,10 @@ bool ChannelInfo::RemoveMLock(ChannelMode *mode, const Anope::string &param)
const ModeLock &ml = it->second;
if (ml.param == param)
{
+ EventReturn MOD_RESULT;
+ FOREACH_RESULT(I_OnUnMLock, OnUnMLock(this, &it->second));
+ if (MOD_RESULT == EVENT_STOP)
+ return false;
this->mode_locks.erase(it);
return true;
}
diff --git a/src/tools/db-convert.cpp b/src/tools/db-convert.cpp
deleted file mode 100644
index 16dc3516a..000000000
--- a/src/tools/db-convert.cpp
+++ /dev/null
@@ -1,1032 +0,0 @@
-/*
- * Copyright (C) 2003-2011 Anope Team <team@anope.org>
- * Copyright (C) 2005-2006 Florian Schulze <certus@anope.org>
- * Copyright (C) 2008-2011 Robin Burchell <w00t@inspircd.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License (see it online
- * at http://www.gnu.org/copyleft/gpl.html) as published by the Free
- * Software Foundation;
- *
- * 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.
- */
-
-#include "db-convert.h"
-
-static std::string GetLevelName(int level)
-{
- switch (level)
- {
- case 0:
- return "INVITE";
- case 1:
- return "AKICK";
- case 2:
- return "SET";
- case 3:
- return "UNBAN";
- case 4:
- return "AUTOOP";
- case 5:
- return "AUTODEOP";
- case 6:
- return "AUTOVOICE";
- case 7:
- return "OPDEOP";
- case 8:
- return "LIST";
- case 9:
- return "CLEAR";
- case 10:
- return "NOJOIN";
- case 11:
- return "CHANGE";
- case 12:
- return "MEMO";
- case 13:
- return "ASSIGN";
- case 14:
- return "BADWORDS";
- case 15:
- return "NOKICK";
- case 16:
- return "FANTASIA";
- case 17:
- return "SAY";
- case 18:
- return "GREET";
- case 19:
- return "VOICEME";
- case 20:
- return "VOICE";
- case 21:
- return "GETKEY";
- case 22:
- return "AUTOHALFOP";
- case 23:
- return "AUTOPROTECT";
- case 24:
- return "OPDEOPME";
- case 25:
- return "HALFOPME";
- case 26:
- return "HALFOP";
- case 27:
- return "PROTECTME";
- case 28:
- return "PROTECT";
- case 29:
- return "KICKME";
- case 30:
- return "KICK";
- case 31:
- return "SIGNKICK";
- case 32:
- return "BANME";
- case 33:
- return "BAN";
- case 34:
- return "TOPIC";
- case 35:
- return "INFO";
- default:
- return "INVALID";
- }
-}
-
-void process_mlock_modes(std::ofstream &fs, size_t m, const std::string &ircd)
-{
- /* this is the same in all protocol modules */
- if (m & 0x1) fs << " CMODE_INVITE"; // CMODE_i
- if (m & 0x2) fs << " CMODE_MODERATED"; // CMODE_m
- if (m & 0x4) fs << " CMODE_NOEXTERNAL"; // CMODE_n
- if (m & 0x8) fs << " CMODE_PRIVATE"; // CMODE_p
- if (m & 0x10) fs << " CMODE_SECRET"; // CMODE_s
- if (m & 0x20) fs << " CMODE_TOPIC"; // CMODE_t
- if (m & 0x40) fs << " CMODE_KEY"; // CMODE_k
- if (m & 0x80) fs << " CMODE_LIMIT"; // CMODE_l
- if (m & 0x200) fs << " CMODE_REGISTERED"; // CMODE_r
-
- if (ircd == "unreal" || ircd == "inspircd")
- {
- if (m & 0x100) fs << " CMODE_REGISTEREDONLY"; // CMODE_R
- if (m & 0x400) fs << " CMODE_BLOCKCOLOR"; // CMODE_c
- if (m & 0x2000) fs << " CMODE_NOKNOCK"; // CMODE_K
- if (m & 0x4000) fs << " CMODE_REDIRECT"; // CMODE_L
- if (m & 0x8000) fs << " CMODE_OPERONLY"; // CMODE_O
- if (m & 0x10000) fs << " CMODE_NOKICK"; // CMODE_Q
- if (m & 0x20000) fs << " CMODE_STRIPCOLOR"; // CMODE_S
- if (m & 0x80000) fs << " CMODE_FLOOD"; // CMODE_f
- if (m & 0x100000) fs << " CMODE_FILTER"; // CMODE_G
- if (m & 0x200000) fs << " CMODE_NOCTCP"; // CMODE_C
- if (m & 0x400000) fs << " CMODE_AUDITORIUM"; // CMODE_u
- if (m & 0x800000) fs << " CMODE_SSL"; // CMODE_z
- if (m & 0x1000000) fs << " CMODE_NONICK"; // CMODE_N
- if (m & 0x4000000) fs << " CMODE_REGMODERATED"; // CMODE_M
- }
-
- if (ircd == "unreal")
- {
- if (m & 0x800) fs << " CMODE_ADMINONLY"; // CMODE_A
- if (m & 0x40000) fs << " CMODE_NOINVITE"; // CMODE_f
- if (m & 0x2000000) fs << " CMODE_NONOTICE"; // CMODE_T
- if (m & 0x8000000) fs << " CMODE_JOINFLOOD"; // CMODE_j
- }
- if (ircd == "inspircd" )
- {
- if (m & 0x800) fs << " CMODE_ALLINVITE"; // CMODE_A
- if (m & 0x1000) fs << " CMODE_NONOTICE"; // CMODE_T
- /* for some reason, there is no CMODE_P in 1.8.x and no CMODE_V in the 1.9.1 protocol module
- we are ignoring this flag until we find a solution for this problem,
- so the +V/+P mlock mode is lost on convert
- anope 1.8: if (m & 0x40000) fs << " NOINVITE"; // CMODE_V
- anope 1.9: if (m & 0x40000) fs << " PERM"; // CMODE_P
- */
- if (m & 0x2000000) fs << " CMODE_JOINFLOOD"; // CMODE_j
- if (m & 0x8000000) fs << " CMODE_BLOCKCAPS"; // CMODE_B
- if (m & 0x10000000) fs << " CMODE_NICKFLOOD"; // CMODE_F
- //if (m & 0x20000000) fs << ""; // CMODE_g (mode +g <badword>) ... can't be mlocked in older version
- //if (m & 0x40000000) fs << ""; // CMODE_J (mode +J [seconds] ... can't be mlocked in older versions
- }
-}
-
-int main(int argc, char *argv[])
-{
- dbFILE *f;
- std::ofstream fs;
- std::string hashm, ircd;
-
- printf("\n"C_LBLUE"Anope 1.8.x -> 1.9.3+ database converter"C_NONE"\n\n");
-
- while (hashm != "md5" && hashm != "sha1" && hashm != "oldmd5" && hashm != "plain")
- {
- if (!hashm.empty())
- std::cout << "Select a valid option, thanks!" << std::endl;
- std::cout << "Which hash method did you use? (md5, sha1, oldmd5, plain)" << std::endl << "? ";
- std::cin >> hashm;
- }
-
- while (ircd != "bahamut" && ircd != "charybdis" && ircd != "dreamforge" && ircd != "hybrid" && ircd != "inspircd" && ircd != "plexus2" && ircd != "plexus3" && ircd != "ptlink" && ircd != "rageircd" && ircd != "ratbox" && ircd != "shadowircd" && ircd != "solidircd" && ircd != "ultimate2" && ircd != "ultimate3" && ircd != "unreal" && ircd != "viagra")
- {
- if (!ircd.empty())
- std::cout << "Select a valid option!" << std::endl;
- std::cout << "Which IRCd did you use? (required for converting the mlock modes)" << std::endl;
- std::cout << "(bahamut, charybdis, dreamforge, hybrid, inspircd, plexus2, plexus3, ptlink," << std::endl;
- std::cout << "rageircd, ratbox, shadowircd, solidircd, ultimate2, ultimate3, unreal, viagra)" << std::endl;
- std::cout << "Your IRCd: "; std::cin >> ircd;
- }
-
- std::cout << "You selected " << hashm << std::endl;
-
- fs.clear();
- fs.open("anope.db");
- if (!fs.is_open())
- {
- printf("\n"C_LBLUE"Could not open anope.db for write"C_NONE"\n\n");
- exit(1);
- }
-
- fs << "VER 2" << std::endl;
-
- /* Section I: Nicks */
- /* Ia: First database */
- if ((f = open_db_read("NickServ", "nick.db", 14)))
- {
- NickAlias *na, **nalast, *naprev;
- NickCore *nc, **nclast, *ncprev;
- int16 tmp16;
- int32 tmp32;
- int i, j, c;
-
- printf("Trying to merge nicks...\n");
-
- /* Nick cores */
- for (i = 0; i < 1024; ++i)
- {
- nclast = &nclists[i];
- ncprev = NULL;
-
- while ((c = getc_db(f)) == 1)
- {
- if (c != 1)
- {
- printf("Invalid format in nickserv db.\n");
- exit(0);
- }
-
- nc = new NickCore;
- nc->aliascount = 0;
- nc->unused = 0;
-
- *nclast = nc;
- nclast = &nc->next;
- nc->prev = ncprev;
- ncprev = nc;
-
- READ(read_string(&nc->display, f));
- READ(read_buffer(nc->pass, f));
- READ(read_string(&nc->email, f));
- READ(read_string(&nc->greet, f));
- READ(read_uint32(&nc->icq, f));
- READ(read_string(&nc->url, f));
- READ(read_uint32(&nc->flags, f));
- READ(read_uint16(&nc->language, f));
- READ(read_uint16(&nc->accesscount, f));
- if (nc->accesscount)
- {
- char **access = new char *[nc->accesscount + 1];
- nc->access = access;
- for (j = 0; j < nc->accesscount; ++j, ++access)
- READ(read_string(access, f));
- }
- READ(read_int16(&nc->memos.memocount, f));
- READ(read_int16(&nc->memos.memomax, f));
- if (nc->memos.memocount)
- {
- Memo *memos = new Memo[nc->memos.memocount];
- nc->memos.memos = memos;
- for (j = 0; j < nc->memos.memocount; ++j, ++memos)
- {
- READ(read_uint32(&memos->number, f));
- READ(read_uint16(&memos->flags, f));
- READ(read_int32(&tmp32, f));
- memos->time = tmp32;
- READ(read_buffer(memos->sender, f));
- READ(read_string(&memos->text, f));
- }
- }
- READ(read_uint16(&nc->channelcount, f));
- READ(read_int16(&tmp16, f));
- } /* getc_db() */
- *nclast = NULL;
- } /* for() loop */
-
- /* Nick aliases */
- for (i = 0; i < 1024; ++i)
- {
- char *s = NULL;
-
- nalast = &nalists[i];
- naprev = NULL;
-
- while ((c = getc_db(f)) == 1)
- {
- if (c != 1)
- {
- printf("Invalid format in nick db.\n");
- exit(0);
- }
-
- na = new NickAlias;
-
- READ(read_string(&na->nick, f));
- READ(read_string(&na->last_usermask, f));
- READ(read_string(&na->last_realname, f));
- READ(read_string(&na->last_quit, f));
-
- READ(read_int32(&tmp32, f));
- na->time_registered = tmp32;
- READ(read_int32(&tmp32, f));
- na->last_seen = tmp32;
- READ(read_uint16(&na->status, f));
- READ(read_string(&s, f));
- na->nc = findcore(s, 0);
- ++na->nc->aliascount;
- //free(s);
- delete [] s;
-
- *nalast = na;
- nalast = &na->next;
- na->prev = naprev;
- naprev = na;
- } /* getc_db() */
- *nalast = NULL;
- } /* for() loop */
- close_db(f); /* End of section Ia */
- }
-
- /* CLEAN THE CORES */
- int i;
- for (i = 0; i < 1024; ++i)
- {
- NickCore *ncnext;
- for (NickCore *nc = nclists[i]; nc; nc = ncnext)
- {
- ncnext = nc->next;
- if (nc->aliascount < 1)
- {
- printf("Deleting core %s (%s).\n", nc->display, nc->email);
- delcore(nc);
- }
- }
- }
-
- head = NULL;
- if ((f = open_db_read("HostServ", "hosts.db", 3)))
- {
- int c;
- HostCore *hc;
-
- while ((c = getc_db(f)) == 1)
- {
- hc = new HostCore;
- READ(read_string(&hc->nick, f));
- READ(read_string(&hc->vIdent, f));
- READ(read_string(&hc->vHost, f));
- READ(read_string(&hc->creator, f));
- READ(read_int32(&hc->time, f));
-
- hc->next = head;
- head = hc;
- }
-
- close_db(f);
- }
-
- /* Nick cores */
- for (i = 0; i < 1024; ++i)
- {
- NickAlias *na;
- NickCore *nc;
- char **access;
- Memo *memos;
- int j, len;
- std::string cpass;
- for (nc = nclists[i]; nc; nc = nc->next)
- {
- if (!nc->display)
- {
- std::cout << "Skipping core with no display" << std::endl;
- continue;
- }
-
- if (nc->aliascount < 1)
- {
- std::cout << "Skipping core with 0 or less aliases (wtf?)" << std::endl;
- continue;
- }
-
- if (nc->flags & 0x80000000)
- {
- std::cout << "Skipping forbidden nick " << nc->display << std::endl;
- continue;
- }
-
- // Enc pass
- if (hashm == "plain")
- len = strlen(nc->pass);
- else if (hashm == "md5")
- len = 16;
- else if (hashm == "sha1")
- len = 20;
- else if (hashm == "oldmd5")
- len = 16;
- else
- len = 32;
-
- if (hashm == "plain")
- b64_encode(nc->pass, cpass);
- else
- cpass = Hex(nc->pass);
-
- fs << "NC " << nc->display << " " << hashm << ":" << cpass << std::endl;
- fs << "MD LANGUAGE " << GetLanguageID(nc->language) << std::endl;
- fs << "MD MEMOMAX " << nc->memos.memomax << std::endl;
- fs << "MD CHANCOUNT " << nc->channelcount << std::endl;
-
- std::cout << "Wrote account for " << nc->display << " passlen " << cpass.length() << std::endl;
- if (nc->email)
- fs << "MD EMAIL " << nc->email << std::endl;
- if (nc->greet)
- fs << "MD GREET :" << nc->greet << std::endl;
- if (nc->icq)
- fs << "MD ICQ :" << nc->icq << std::endl;
- if (nc->url)
- fs << "MD URL :" << nc->url << std::endl;
-
- if (nc->accesscount)
- for (j = 0, access = nc->access; j < nc->accesscount && *access; ++j, ++access)
- fs << "MD ACCESS " << *access << std::endl;
-
- fs << "MD FLAGS "
- << (nc->flags & NI_KILLPROTECT ? "KILLPROTECT " : "")
- << (nc->flags & NI_SECURE ? "SECURE " : "")
- << (nc->flags & NI_MSG ? "MSG " : "")
- << (nc->flags & NI_MEMO_HARDMAX ? "MEMO_HARDMAX " : "")
- << (nc->flags & NI_MEMO_SIGNON ? "MEMO_SIGNON " : "")
- << (nc->flags & NI_MEMO_RECEIVE ? "MEMO_RECEIVE " : "")
- << (nc->flags & NI_PRIVATE ? "PRIVATE " : "")
- << (nc->flags & NI_HIDE_EMAIL ? "HIDE_EMAIL " : "")
- << (nc->flags & NI_HIDE_MASK ? "HIDE_MASK " : "")
- << (nc->flags & NI_HIDE_QUIT ? "HIDE_QUIT " : "")
- << (nc->flags & NI_KILL_QUICK ? "KILL_QUICK " : "")
- << (nc->flags & NI_KILL_IMMED ? "KILL_IMMED " : "")
- << (nc->flags & NI_MEMO_MAIL ? "MEMO_MAIL " : "")
- << (nc->flags & NI_HIDE_STATUS ? "HIDE_STATUS " : "")
- << (nc->flags & NI_SUSPENDED ? "SUSPENDED " : "")
- // in 1.8, the AUTOOP flag was set to disable AUTOOP. Now we enable it. --DP
- << (!(nc->flags & NI_AUTOOP) ? "AUTOOP " : "")
- << (nc->flags & NI_FORBIDDEN ? "FORBIDDEN " : "") << std::endl;
- if (nc->memos.memocount)
- {
- memos = nc->memos.memos;
- for (j = 0; j < nc->memos.memocount; ++j, ++memos)
- {
- if (!memos->text || !memos->sender)
- continue;
- fs << "MD MI " << memos->time << " " << memos->sender;
- if (memos->flags & MF_UNREAD)
- fs << " UNREAD";
- if (memos->flags & MF_RECEIPT)
- fs << " RECEIPT";
- if (memos->flags & MF_NOTIFYS)
- fs << " NOTIFYS";
- fs << " :" << memos->text << std::endl;
- }
- }
-
- /* we could do this in a seperate loop, I'm doing it here for tidiness. */
- for (int tmp = 0; tmp < 1024; ++tmp)
- {
- for (na = nalists[tmp]; na; na = na->next)
- {
- if (!na->nc)
- {
- std::cout << "Skipping alias with no core (wtf?)" << std::endl;
- continue;
- }
-
- if (na->nc != nc)
- continue;
-
- std::cout << "Writing: " << na->nc->display << "'s nick: " << na->nick << std::endl;
-
- fs << "NA " << na->nc->display << " " << na->nick << " " << na->time_registered << " " << na->last_seen << std::endl;
- if (na->last_usermask)
- fs << "MD LAST_USERMASK " << na->last_usermask << std::endl;
- if (na->last_realname)
- fs << "MD LAST_REALNAME :" << na->last_realname << std::endl;
- if (na->last_quit)
- fs << "MD LAST_QUIT :" << na->last_quit << std::endl;
- if ((na->status & NS_FORBIDDEN) || (na->status & NS_NO_EXPIRE))
- fs << "MD FLAGS" << (na->status & NS_FORBIDDEN ? " FORBIDDEN" : "") << (na->status & NS_NO_EXPIRE ? " NOEXPIRE" : "") << std::endl;
-
- HostCore *hc = findHostCore(na->nick);
- if (hc && hc->creator && hc->vHost)
- fs << "MD VHOST " << hc->creator << " " << hc->time << " " << hc->vHost << " :" << (hc->vIdent ? hc->vIdent : "") << std::endl;
- }
- }
- }
- }
-
- /* Section II: Bots */
- /* IIa: First database */
- if ((f = open_db_read("Botserv", "bot.db", 10)))
- {
- std::string input;
- int c, broken = 0;
- int32 created;
- int16 flags, chancount;
- char *nick, *user, *host, *real;
-
- std::cout << "Trying to convert bots..." << std::endl;
-
- while (input != "y" && input != "n")
- {
- std::cout << std::endl << "Are you converting a 1.9.0 database? (y/n) " << std::endl << "? ";
- std::cin >> input;
- }
- if (input == "y")
- broken = 1;
- input = "";
- while (input != "y" && input != "n")
- {
- std::cout << std::endl << "Are you converting a 1.8.x database? (y/n) " << std::endl << "? ";
- std::cin >> input;
- }
- /* 1.8 doesn't have nickserv etc in bot.db, create them */
- if (input == "y")
- {
- time_t now = time(NULL);
- fs << "BI NickServ NickServ services.anope.org " << now << " 0 :NickServ" << std::endl;
- fs << "MD FLAGS NICKSERV" << std::endl;
-
- fs << "BI ChanServ ChanServ services.anope.org " << now << " 0 :ChanServ" << std::endl;
- fs << "MD FLAGS CHANSERV" << std::endl;
-
- fs << "BI BotServ BotServ services.anope.org " << now << " 0 :BotServ" << std::endl;
- fs << "MD FLAGS BOTSERV" << std::endl;
-
- fs << "BI HostServ HostServ services.anope.org " << now << " 0 :HostServ" << std::endl;
- fs << "MD FLAGS HOSTSERV" << std::endl;
-
- fs << "BI OperServ OperServ services.anope.org " << now << " 0 :OperServ" << std::endl;
- fs << "MD FLAGS OPERSERV" << std::endl;
-
- fs << "BI MemoServ MemoServ services.anope.org " << now << " 0 :MemoServ" << std::endl;
- fs << "MD FLAGS MEMOSERV" << std::endl;
-
- fs << "BI Global Global services.anope.org " << now << " 0: Global" << std::endl;
- fs << "MD FLAGS GLOBAL" << std::endl;
- }
-
- while ((c = getc_db(f)) == 1)
- {
- READ(read_string(&nick, f));
- READ(read_string(&user, f));
- READ(read_string(&host, f));
- READ(read_string(&real, f));
- SAFE(read_int16(&flags, f));
- READ(read_int32(&created, f));
- READ(read_int16(&chancount, f));
-
- if (!created)
- created = time(NULL); // Unfortunatley, we forgot to store the created bot time in 1.9.1+
-
- /* fix for the 1.9.0 broken bot.db */
- if (broken)
- {
- flags = 0;
- if (!mystricmp(nick, "ChanServ"))
- flags |= BI_CHANSERV;
- if (!mystricmp(nick, "BotServ"))
- flags |= BI_BOTSERV;
- if (!mystricmp(nick, "HostServ"))
- flags |= BI_HOSTSERV;
- if (!mystricmp(nick, "OperServ"))
- flags |= BI_OPERSERV;
- if (!mystricmp(nick, "MemoServ"))
- flags |= BI_MEMOSERV;
- if (!mystricmp(nick, "NickServ"))
- flags |= BI_NICKSERV;
- if (!mystricmp(nick, "Global"))
- flags |= BI_GLOBAL;
- } /* end of 1.9.0 broken database fix */
- std::cout << "Writing Bot " << nick << "!" << user << "@" << host << std::endl;
- fs << "BI " << nick << " " << user << " " << host << " " << created << " " << chancount << " :" << real << std::endl;
- fs << "MD FLAGS"
- << (flags & BI_PRIVATE ? " PRIVATE" : "")
- << (flags & BI_CHANSERV ? " CHANSERV" : "")
- << (flags & BI_BOTSERV ? " BOTSERV" : "")
- << (flags & BI_HOSTSERV ? " HOSTSERV" : "")
- << (flags & BI_OPERSERV ? " OPERSERV" : "")
- << (flags & BI_MEMOSERV ? " MEMOSERV" : "")
- << (flags & BI_NICKSERV ? " NICKSERV" : "")
- << (flags & BI_GLOBAL ? " GLOBAL" : "") << std::endl;
- }
- close_db(f);
- }
-
- /* Section III: Chans */
- // IIIa: First database
- if ((f = open_db_read("ChanServ", "chan.db", 16)))
- {
- ChannelInfo *ci, **last, *prev;
- int c;
-
- printf("Trying to merge channels...\n");
-
- for (i = 0; i < 256; ++i)
- {
- int16 tmp16;
- int32 tmp32;
- int n_levels;
- char *s;
- int n_ttb;
-
- last = &chanlists[i];
- prev = NULL;
-
- while ((c = getc_db(f)) == 1)
- {
- int j;
-
- if (c != 1)
- {
- printf("Invalid format in chans.db.\n");
- exit(0);
- }
-
- ci = new ChannelInfo;
- *last = ci;
- last = &ci->next;
- ci->prev = prev;
- prev = ci;
- READ(read_buffer(ci->name, f));
- READ(read_string(&ci->founder, f));
- READ(read_string(&ci->successor, f));
- READ(read_buffer(ci->founderpass, f));
- READ(read_string(&ci->desc, f));
- if (!ci->desc)
- ci->desc = strdup("");
- std::cout << "Read " << ci->name << " founder " << (ci->founder ? ci->founder : "N/A") << std::endl;
- READ(read_string(&ci->url, f));
- READ(read_string(&ci->email, f));
- READ(read_int32(&tmp32, f));
- ci->time_registered = tmp32;
- READ(read_int32(&tmp32, f));
- ci->last_used = tmp32;
- READ(read_string(&ci->last_topic, f));
- READ(read_buffer(ci->last_topic_setter, f));
- READ(read_int32(&tmp32, f));
- ci->last_topic_time = tmp32;
- READ(read_uint32(&ci->flags, f));
- // Temporary flags cleanup
- ci->flags &= ~0x80000000;
- READ(read_string(&ci->forbidby, f));
- READ(read_string(&ci->forbidreason, f));
- READ(read_int16(&tmp16, f));
- ci->bantype = tmp16;
- READ(read_int16(&tmp16, f));
- n_levels = tmp16;
- ci->levels = new int16[36];
- for (j = 0; j < n_levels; ++j)
- {
- if (j < 36)
- READ(read_int16(&ci->levels[j], f));
- else
- READ(read_int16(&tmp16, f));
- }
- READ(read_uint16(&ci->accesscount, f));
- if (ci->accesscount)
- {
- ci->access = new ChanAccess[ci->accesscount];
- for (j = 0; j < ci->accesscount; ++j)
- {
- READ(read_uint16(&ci->access[j].in_use, f));
- if (ci->access[j].in_use)
- {
- READ(read_int16(&ci->access[j].level, f));
- READ(read_string(&s, f));
- if (s)
- {
- ci->access[j].nc = findcore(s, 0);
- delete [] s;
- }
- if (ci->access[j].nc == NULL)
- ci->access[j].in_use = 0;
- READ(read_int32(&tmp32, f));
- ci->access[j].last_seen = tmp32;
- }
- }
- }
- else
- ci->access = NULL;
- READ(read_uint16(&ci->akickcount, f));
- if (ci->akickcount)
- {
- ci->akick = new AutoKick[ci->akickcount];
- for (j = 0; j < ci->akickcount; ++j)
- {
- SAFE(read_uint16(&ci->akick[j].flags, f));
- if (ci->akick[j].flags & 0x0001)
- {
- SAFE(read_string(&s, f));
- if (ci->akick[j].flags & 0x0002)
- {
- ci->akick[j].u.nc = findcore(s, 0);
- if (!ci->akick[j].u.nc)
- ci->akick[j].flags &= ~0x0001;
- delete [] s;
- }
- else
- ci->akick[j].u.mask = s;
- SAFE(read_string(&s, f));
- if (ci->akick[j].flags & 0x0001)
- ci->akick[j].reason = s;
- else if (s)
- delete [] s;
- SAFE(read_string(&s, f));
- if (ci->akick[j].flags & 0x0001)
- ci->akick[j].creator = s;
- else if (s)
- delete [] s;
- SAFE(read_int32(&tmp32, f));
- if (ci->akick[j].flags & 0x0001)
- ci->akick[j].addtime = tmp32;
- }
- }
- }
- else
- ci->akick = NULL;
- READ(read_uint32(&ci->mlock_on, f));
- READ(read_uint32(&ci->mlock_off, f));
- READ(read_uint32(&ci->mlock_limit, f));
- READ(read_string(&ci->mlock_key, f));
- READ(read_string(&ci->mlock_flood, f));
- READ(read_string(&ci->mlock_redirect, f));
- READ(read_int16(&ci->memos.memocount, f));
- READ(read_int16(&ci->memos.memomax, f));
- if (ci->memos.memocount)
- {
- Memo *memos = new Memo[ci->memos.memocount];
- ci->memos.memos = memos;
- for (j = 0; j < ci->memos.memocount; ++j, ++memos)
- {
- READ(read_uint32(&memos->number, f));
- READ(read_uint16(&memos->flags, f));
- READ(read_int32(&tmp32, f));
- memos->time = tmp32;
- READ(read_buffer(memos->sender, f));
- READ(read_string(&memos->text, f));
- }
- }
- READ(read_string(&ci->entry_message, f));
-
- // BotServ options
- READ(read_string(&ci->bi, f));
- READ(read_int32(&tmp32, f));
- ci->botflags = tmp32;
- READ(read_int16(&tmp16, f));
- n_ttb = tmp16;
- ci->ttb = new int16[16];
- for (j = 0; j < n_ttb; ++j)
- {
- if (j < 8)
- READ(read_int16(&ci->ttb[j], f));
- else
- READ(read_int16(&tmp16, f));
- }
- for (j = n_ttb; j < 8; ++j)
- ci->ttb[j] = 0;
- READ(read_int16(&tmp16, f));
- ci->capsmin = tmp16;
- READ(read_int16(&tmp16, f));
- ci->capspercent = tmp16;
- READ(read_int16(&tmp16, f));
- ci->floodlines = tmp16;
- READ(read_int16(&tmp16, f));
- ci->floodsecs = tmp16;
- READ(read_int16(&tmp16, f));
- ci->repeattimes = tmp16;
-
- READ(read_uint16(&ci->bwcount, f));
- if (ci->bwcount)
- {
- ci->badwords = new BadWord[ci->bwcount];
- for (j = 0; j < ci->bwcount; ++j)
- {
- SAFE(read_uint16(&ci->badwords[j].in_use, f));
- if (ci->badwords[j].in_use)
- {
- SAFE(read_string(&ci->badwords[j].word, f));
- SAFE(read_uint16(&ci->badwords[j].type, f));
- }
- }
- }
- else
- ci->badwords = NULL;
- }
- *last = NULL;
- }
-
- close_db(f);
- }
-
- ChannelInfo *ci;
-
- for (i = 0; i < 256; ++i)
- {
- for (ci = chanlists[i]; ci; ci = ci->next)
- {
- int j;
-
- fs << "CH " << ci->name << " " << ci->time_registered << " " << ci->last_used << std::endl;
- if (ci->founder)
- fs << "MD FOUNDER " << ci->founder << std::endl;
- if (ci->successor)
- fs << "MD SUCCESSOR " << ci->successor << std::endl;
- fs << "MD BANTYPE " << ci->bantype << std::endl;
- fs << "MD MEMOMAX " << ci->memos.memomax << std::endl;
- fs << "MD LEVELS";
- for (j = 0; j < 36; ++j)
- {
- /* In 1.8 disabled meant founder only. In 1.9.2 disabled literally means its disabled so, we will set these to ACCESS_QOP */
- if (ci->levels[j] == -10000)
- fs << " " << GetLevelName(j) << " " << 10000;
- else
- fs << " " << GetLevelName(j) << " " << ci->levels[j];
- }
- fs << std::endl;
- fs << "MD FLAGS"
- << (ci->flags & CI_KEEPTOPIC ? " KEEPTOPIC" : "")
- << (ci->flags & CI_SECUREOPS ? " SECUREOPS" : "")
- << (ci->flags & CI_PRIVATE ? " PRIVATE" : "")
- << (ci->flags & CI_TOPICLOCK ? " TOPICLOCK" : "")
- << (ci->flags & CI_RESTRICTED ? " RESTRICTED" : "")
- << (ci->flags & CI_PEACE ? " PEACE" : "")
- << (ci->flags & CI_SECURE ? " SECURE" : "")
- << (ci->flags & CI_FORBIDDEN ? " FORBIDDEN" : "")
- << (ci->flags & CI_NO_EXPIRE ? " NO_EXPIRE" : "")
- << (ci->flags & CI_MEMO_HARDMAX ? " MEMO_HARDMAX" : "")
- << (ci->flags & CI_OPNOTICE ? " OPNOTICE" : "")
- << (ci->flags & CI_SECUREFOUNDER ? " SECUREFOUNDER" : "")
- << (ci->flags & CI_SIGNKICK ? " SIGNKICK" : "")
- << (ci->flags & CI_SIGNKICK_LEVEL ? " SIGNKICKLEVEL" : "")
- << (ci->flags & CI_XOP ? " XOP" : "")
- << (ci->flags & CI_SUSPENDED ? " SUSPENDED" : "") << std::endl;
- if (ci->desc && *ci->desc)
- fs << "MD DESC :" << ci->desc << std::endl;
- if (ci->url)
- fs << "MD URL :" << ci->url << std::endl;
- if (ci->email)
- fs << "MD EMAIL :" << ci->email << std::endl;
- if (ci->last_topic && ci->last_topic_setter) // MD CH topic <setter> <time> :topic
- fs << "MD TOPIC " << ci->last_topic_setter << " " << ci->last_topic_time << " :" << ci->last_topic << std::endl;
- if (ci->flags & CI_FORBIDDEN)
- fs << "MD FORBID " << (ci->forbidby ? ci->forbidby : "db-convert") << " :" << (ci->forbidreason ? ci->forbidreason : "no reason given") << std::endl;
-
- for (j = 0; j < ci->accesscount; ++j)
- // MD ACCESS <display> <level> <last_seen> <creator> - creator isn't in 1.9.0-1, but is in 1.9.2
- if (ci->access[j].in_use)
- fs << "MD ACCESS " << ci->access[j].nc->display << " " << ci->access[j].level << " " << ci->access[j].last_seen << " Unknown" << std::endl;
-
- for (j = 0; j < ci->akickcount; ++j)
- // MD AKICK <STUCK/UNSTUCK> <NICK/MASK> <akick> <creator> <addtime> :<reason>
- if (ci->akick[j].flags & 0x0001)
- {
- fs << "MD AKICK "
- << (ci->akick[j].flags & AK_STUCK ? "STUCK " : "UNSTUCK ")
- << (ci->akick[j].flags & AK_ISNICK ? "NICK " : "MASK ")
- << (ci->akick[j].flags & AK_ISNICK ? ci->akick[j].u.nc->display : ci->akick[j].u.mask)
- << " " << ci->akick[j].creator << " " << ci->akick[j].addtime << " 0 :"; // 0 is for last used, added in 1.9.2
- if (ci->akick[j].reason)
- fs << ci->akick[j].reason;
- fs << std::endl;
- }
-
- if (ci->mlock_on)
- {
- fs << "MD MLOCK_ON";
- process_mlock_modes(fs, ci->mlock_on, ircd);
- fs << std::endl;
- }
- if (ci->mlock_off)
- {
- fs << "MD MLOCK_OFF";
- process_mlock_modes(fs, ci->mlock_off, ircd);
- fs << std::endl;
- }
- if (ci->mlock_limit)
- fs << "MD MLP CMODE_LIMIT " << ci->mlock_limit << std::endl;
- if (ci->mlock_key && *ci->mlock_key)
- fs << "MD MLP CMODE_KEY " << ci->mlock_key << std::endl;
- if (ci->mlock_flood && *ci->mlock_flood)
- fs << "MD MLP CMODE_FLOOD " << ci->mlock_flood << std::endl;
- if (ci->mlock_redirect && *ci->mlock_redirect)
- fs << "MD MLP CMODE_REDIRECT " << ci->mlock_redirect << std::endl;
- if (ci->memos.memocount)
- {
- Memo *memos = ci->memos.memos;
- for (j = 0; j < ci->memos.memocount; ++j, ++memos)
- {
- fs << "MD MI " << memos->number << " " << memos->time << " " << memos->sender;
- if (memos->flags & MF_UNREAD)
- fs << " UNREAD";
- if (memos->flags & MF_RECEIPT)
- fs << " RECEIPT";
- if (memos->flags & MF_NOTIFYS)
- fs << " NOTIFYS";
- fs << " :" << memos->text << std::endl;
- }
- }
-
- if (ci->entry_message)
- fs << "MD ENTRYMSG :" << ci->entry_message << std::endl;
- if (ci->bi) // here is "bi" a *Char, not a pointer to BotInfo !
- fs << "MD BI NAME " << ci->bi << std::endl;
- if (ci->botflags)
- fs << "MD BI FLAGS"
- << (ci->botflags & BS_DONTKICKOPS ? " DONTKICKOPS" : "" )
- << (ci->botflags & BS_DONTKICKVOICES ? " DONTKICKVOICES" : "")
- << (ci->botflags & BS_FANTASY ? " FANTASY" : "")
- << (ci->botflags & BS_SYMBIOSIS ? " SYMBIOSIS" : "")
- << (ci->botflags & BS_GREET ? " GREET" : "")
- << (ci->botflags & BS_NOBOT ? " NOBOT" : "")
- << (ci->botflags & BS_KICK_BOLDS ? " KICK_BOLDS" : "")
- << (ci->botflags & BS_KICK_COLORS ? " KICK_COLORS" : "")
- << (ci->botflags & BS_KICK_REVERSES ? " KICK_REVERSES" : "")
- << (ci->botflags & BS_KICK_UNDERLINES ? " KICK_UNDERLINES" : "")
- << (ci->botflags & BS_KICK_BADWORDS ? " KICK_BADWORDS" : "")
- << (ci->botflags & BS_KICK_CAPS ? " KICK_CAPS" : "")
- << (ci->botflags & BS_KICK_FLOOD ? " KICK_FLOOD" : "")
- << (ci->botflags & BS_KICK_REPEAT ? " KICK_REPEAT" : "") << std::endl;
- fs << "MD BI TTB";
- fs << " BOLDS " << ci->ttb[0];
- fs << " COLORS " << ci->ttb[1];
- fs << " REVERSES " << ci->ttb[2];
- fs << " UNDERLINES " << ci->ttb[3];
- fs << " BADWORDS " << ci->ttb[4];
- fs << " CAPS " << ci->ttb[5];
- fs << " FLOOD " << ci->ttb[6];
- fs << " REPEAT " << ci->ttb[7];
- fs << std::endl;
- if (ci->capsmin)
- fs << "MD BI CAPSMINS " << ci->capsmin << std::endl;
- if (ci->capspercent)
- fs << "MD BI CAPSPERCENT " << ci->capspercent << std::endl;
- if (ci->floodlines)
- fs << "MD BI FLOODLINES " << ci->floodlines << std::endl;
- if (ci->floodsecs)
- fs << "MD BI FLOODSECS " << ci->floodsecs << std::endl;
- if (ci->repeattimes)
- fs << "MD BI REPEATTIMES " << ci->repeattimes << std::endl;
- for (j = 0; j < ci->bwcount; ++j)
- if (ci->badwords[j].in_use)
- {
- fs << "MD BI BADWORD "
- << (!ci->badwords[j].type ? "ANY " : "")
- << (ci->badwords[j].type == 1 ? "SINGLE " : "")
- << (ci->badwords[j].type == 2 ? "START " : "")
- << (ci->badwords[j].type == 3 ? "END " : "")
- << ":" << ci->badwords[j].word << std::endl;
- }
-
- } /* for (chanlists[i]) */
- } /* for (i) */
-
- /*********************************/
- /* OPERSERV Section */
- /*********************************/
-
- if ((f = open_db_read("OperServ", "oper.db", 13)))
- {
- int32 maxusercnt = 0, maxusertime = 0, seton = 0, expires = 0;
- int16 capacity = 0;
- char *user, *host, *by, *reason, *mask;
-
- std::cout << "Writing operserv data (stats, akills, sglines, szlines)" << std::endl;
-
- SAFE(read_int32(&maxusercnt, f));
- SAFE(read_int32(&maxusertime, f));
- fs << "OS STATS " << maxusercnt << " " << maxusertime << std::endl;
-
- /* AKILLS */
- read_int16(&capacity, f);
- for (i = 0; i < capacity; ++i)
- {
- SAFE(read_string(&user, f));
- SAFE(read_string(&host, f));
- SAFE(read_string(&by, f));
- SAFE(read_string(&reason, f));
- SAFE(read_int32(&seton, f));
- SAFE(read_int32(&expires, f));
- fs << "OS AKILL " << user << " " << host << " " << by << " " << seton << " " << expires << " :" << reason << std::endl;
- delete [] user;
- delete [] host;
- delete [] by;
- delete [] reason;
- }
- /* SNLINES */
- read_int16(&capacity, f);
- for (i = 0; i < capacity; ++i)
- {
- SAFE(read_string(&mask, f));
- SAFE(read_string(&by, f));
- SAFE(read_string(&reason, f));
- SAFE(read_int32(&seton, f));
- SAFE(read_int32(&expires, f));
- fs << "OS SNLINE " << mask << " " << by << " " << seton << " " << expires << " :" << reason << std::endl;
- delete [] mask;
- delete [] by;
- delete [] reason;
- }
- /* SQLINES */
- read_int16(&capacity, f);
- for (i = 0; i < capacity; ++i)
- {
- SAFE(read_string(&mask, f));
- SAFE(read_string(&by, f));
- SAFE(read_string(&reason, f));
- SAFE(read_int32(&seton, f));
- SAFE(read_int32(&expires, f));
- fs << "OS SQLINE " << mask << " " << by << " " << seton << " " << expires << " :" << reason << std::endl;
- delete [] mask;
- delete [] by;
- delete [] reason;
- }
- /* SZLINES */
- read_int16(&capacity, f);
- for (i = 0; i < capacity; ++i)
- {
- SAFE(read_string(&mask, f));
- SAFE(read_string(&by, f));
- SAFE(read_string(&reason, f));
- SAFE(read_int32(&seton, f));
- SAFE(read_int32(&expires, f));
- fs << "OS SZLINE " << mask << " " << by << " " << seton << " " << expires << " :" << reason << std::endl;
- delete [] mask;
- delete [] by;
- delete [] reason;
- }
- close_db(f);
- } // operserv database
-
- /* CONVERTING DONE \o/ HURRAY! */
- fs.flush();
- fs.close();
- return 0;
-} /* End of main() */
diff --git a/src/tools/db-convert.h b/src/tools/db-convert.h
deleted file mode 100644
index 9ec4a882a..000000000
--- a/src/tools/db-convert.h
+++ /dev/null
@@ -1,975 +0,0 @@
-/*
- * Copyright (C) 2003-2011 Anope Team <team@anope.org>
- * Copyright (C) 2005-2006 Florian Schulze <certus@anope.org>
- * Copyright (C) 2008-2011 Robin Burchell <w00t@inspircd.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License (see it online
- * at http://www.gnu.org/copyleft/gpl.html) as published by the Free
- * Software Foundation;
- *
- * 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.
- */
-
-#ifndef DB_CONVERT_H
-#define DB_CONVERT_H
-
-#include <string>
-#include <iostream>
-#include <fstream>
-
-#include <cstdlib>
-#include <cstring>
-#include <cstdio>
-#include <cctype>
-#include <ctime>
-#include <fcntl.h>
-
-#ifndef _WIN32
-#include <unistd.h>
-#else
-#include <windows.h>
-#include <io.h>
-#endif
-#include "sysconf.h"
-
-#ifndef _WIN32
-#define C_LBLUE "\033[1;34m"
-#define C_NONE "\033[m"
-#else
-#define C_LBLUE ""
-#define C_NONE ""
-#endif
-
-#define getc_db(f) (fgetc((f)->fp))
-#define HASH(nick) ((tolower((nick)[0]) & 31)<<5 | (tolower((nick)[1]) & 31))
-#define HASH2(chan) ((chan)[1] ? ((chan)[1] & 31)<<5 | ((chan)[2] & 31) : 0)
-#define read_buffer(buf, f) (read_db((f), (buf), sizeof(buf)) == sizeof(buf))
-#define write_buffer(buf, f) (write_db((f), (buf), sizeof(buf)) == sizeof(buf))
-#define read_db(f, buf, len) (fread((buf), 1, (len), (f)->fp))
-#define write_db(f, buf, len) (fwrite((buf), 1, (len), (f)->fp))
-#define read_int8(ret, f) ((*(ret) = fgetc((f)->fp)) == EOF ? -1 : 0)
-#define write_int8(val, f) (fputc((val), (f)->fp) == EOF ? -1 : 0)
-#define SAFE(x) \
-if (true) \
-{ \
- if ((x) < 0) \
- printf("Error, the database is broken, trying to continue... no guarantee.\n"); \
-} \
-else \
- static_cast<void>(0)
-#define READ(x) \
-if (true) \
-{ \
- if ((x) < 0) \
- { \
- printf("Error, the database is broken, trying to continue... no guarantee.\n"); \
- exit(0); \
- } \
-} \
-else \
- static_cast<void>(0)
-
-struct Memo
-{
- uint32 number; /* Index number -- not necessarily array position! */
- uint16 flags; /* Flags */
- time_t time; /* When was it sent? */
- char sender[32]; /* Name of the sender */
- char *text;
-};
-
-struct dbFILE
-{
- int mode; /* 'r' for reading, 'w' for writing */
- FILE *fp; /* The normal file descriptor */
- char filename[1024]; /* Name of the database file */
-};
-
-struct MemoInfo
-{
- int16 memocount; /* Current # of memos */
- int16 memomax; /* Max # of memos one can hold*/
- Memo *memos; /* Pointer to original memos */
-};
-
-struct NickCore
-{
- NickCore *next, *prev;
-
- char *display; /* How the nick is displayed */
- char pass[32]; /* Password of the nicks */
- char *email; /* E-mail associated to the nick */
- char *greet; /* Greet associated to the nick */
- uint32 icq; /* ICQ # associated to the nick */
- char *url; /* URL associated to the nick */
- uint32 flags; /* See NI_* below */
- uint16 language; /* Language selected by nickname owner (LANG_*) */
- uint16 accesscount; /* # of entries */
- char **access; /* Array of strings */
- MemoInfo memos; /* Memo information */
- uint16 channelcount; /* Number of channels currently registered */
- int unused; /* Used for nick collisions */
- int aliascount; /* How many aliases link to us? Remove the core if 0 */
-};
-
-struct NickAlias
-{
- NickAlias *next, *prev;
- char *nick; /* Nickname */
- time_t time_registered; /* When the nick was registered */
- time_t last_seen; /* When it was seen online for the last time */
- uint16 status; /* See NS_* below */
- NickCore *nc; /* I'm an alias of this */
-
- char *last_usermask;
- char *last_realname;
- char *last_quit;
-};
-
-struct ChanAccess
-{
- uint16 in_use; /* 1 if this entry is in use, else 0 */
- int16 level;
- NickCore *nc; /* Guaranteed to be non-NULL if in use, NULL if not */
- time_t last_seen;
-};
-
-struct AutoKick
-{
- int16 in_use; /* Always 0 if not in use */
- int16 is_nick; /* 1 if a regged nickname, 0 if a nick!user@host mask */
- uint16 flags;
- union
- {
- char *mask; /* Guaranteed to be non-NULL if in use, NULL if not */
- NickCore *nc; /* Same */
- } u;
- char *reason;
- char *creator;
- time_t addtime;
-};
-
-struct BadWord
-{
- uint16 in_use;
- char *word;
- uint16 type;
-};
-
-struct ChannelInfo
-{
- ChannelInfo *next, *prev;
-
- char name[64]; /* Channel name */
- char *founder; /* Who registered the channel */
- char *successor; /* Who gets the channel if the founder nick is dropped or expires */
- char founderpass[32]; /* Channel password */
- char *desc; /* Description */
- char *url; /* URL */
- char *email; /* Email address */
- time_t time_registered; /* When was it registered */
- time_t last_used; /* When was it used hte last time */
- char *last_topic; /* Last topic on the channel */
- char last_topic_setter[32]; /* Who set the last topic */
- time_t last_topic_time; /* When the last topic was set */
- uint32 flags; /* Flags */
- char *forbidby; /* if forbidden: who did it */
- char *forbidreason; /* if forbidden: why */
- int16 bantype; /* Bantype */
- int16 *levels; /* Access levels for commands */
- uint16 accesscount; /* # of pple with access */
- ChanAccess *access; /* List of authorized users */
- uint16 akickcount; /* # of akicked pple */
- AutoKick *akick; /* List of users to kickban */
- uint32 mlock_on, mlock_off; /* See channel modes below */
- uint32 mlock_limit; /* 0 if no limit */
- char *mlock_key; /* NULL if no key */
- char *mlock_flood; /* NULL if no +f */
- char *mlock_redirect; /* NULL if no +L */
- char *entry_message; /* Notice sent on entering channel */
- MemoInfo memos; /* Memos */
- char *bi; /* Bot used on this channel */
- uint32 botflags; /* BS_* below */
- int16 *ttb; /* Times to ban for each kicker */
- uint16 bwcount; /* Badword count */
- BadWord *badwords; /* For BADWORDS kicker */
- int16 capsmin, capspercent; /* For CAPS kicker */
- int16 floodlines, floodsecs; /* For FLOOD kicker */
- int16 repeattimes; /* For REPEAT kicker */
-};
-
-struct HostCore
-{
- HostCore *next;
- char *nick;
- char *vIdent;
- char *vHost;
- char *creator;
- int32 time;
-};
-
-dbFILE *open_db_read(const char *service, const char *filename, int version);
-NickCore *findcore(const char *nick, int version);
-NickAlias *findnick(const char *nick);
-ChannelInfo *cs_findchan(const char *chan);
-char *strscpy(char *d, const char *s, size_t len);
-int write_file_version(dbFILE * f, uint32 version);
-int mystricmp(const char *s1, const char *s2);
-int delnick(NickAlias *na, int donttouchthelist);
-int write_string(const char *s, dbFILE * f);
-int write_ptr(const void *ptr, dbFILE * f);
-int read_int16(int16 * ret, dbFILE * f);
-int read_int32(int32 * ret, dbFILE * f);
-int read_uint16(uint16 * ret, dbFILE * f);
-int read_uint32(uint32 * ret, dbFILE * f);
-int read_string(char **ret, dbFILE * f);
-int write_int16(uint16 val, dbFILE * f);
-int write_int32(uint32 val, dbFILE * f);
-int read_ptr(void **ret, dbFILE * f);
-int delcore(NickCore *nc);
-void alpha_insert_chan(ChannelInfo * ci);
-void close_db(dbFILE * f);
-
-ChannelInfo *chanlists[256];
-NickAlias *nalists[1024];
-NickCore *nclists[1024];
-HostCore *head = NULL;
-
-void b64_encode(const std::string &src, std::string &target);
-
-/* Memo Flags */
-#define MF_UNREAD 0x0001 /* Memo has not yet been read */
-#define MF_RECEIPT 0x0002 /* Sender requested receipt */
-#define MF_NOTIFYS 0x0004 /* Memo is a notification of receitp */
-
-/* Nickname status flags: */
-#define NS_FORBIDDEN 0x0002 /* Nick may not be registered or used */
-#define NS_NO_EXPIRE 0x0004 /* Nick never expires */
-
-/* Nickname setting flags: */
-#define NI_KILLPROTECT 0x00000001 /* Kill others who take this nick */
-#define NI_SECURE 0x00000002 /* Don't recognize unless IDENTIFY'd */
-#define NI_MSG 0x00000004 /* Use PRIVMSGs instead of NOTICEs */
-#define NI_MEMO_HARDMAX 0x00000008 /* Don't allow user to change memo limit */
-#define NI_MEMO_SIGNON 0x00000010 /* Notify of memos at signon and un-away */
-#define NI_MEMO_RECEIVE 0x00000020 /* Notify of new memos when sent */
-#define NI_PRIVATE 0x00000040 /* Don't show in LIST to non-servadmins */
-#define NI_HIDE_EMAIL 0x00000080 /* Don't show E-mail in INFO */
-#define NI_HIDE_MASK 0x00000100 /* Don't show last seen address in INFO */
-#define NI_HIDE_QUIT 0x00000200 /* Don't show last quit message in INFO */
-#define NI_KILL_QUICK 0x00000400 /* Kill in 20 seconds instead of 60 */
-#define NI_KILL_IMMED 0x00000800 /* Kill immediately instead of in 60 sec */
-#define NI_ENCRYPTEDPW 0x00004000 /* Nickname password is encrypted */
-#define NI_MEMO_MAIL 0x00010000 /* User gets email on memo */
-#define NI_HIDE_STATUS 0x00020000 /* Don't show services access status */
-#define NI_SUSPENDED 0x00040000 /* Nickname is suspended */
-#define NI_AUTOOP 0x00080000 /* Autoop nickname in channels */
-#define NI_NOEXPIRE 0x00100000 /* nicks in this group won't expire */
-
-// Old NS_FORBIDDEN, very fucking temporary.
-#define NI_FORBIDDEN 0x80000000
-
-/* Retain topic even after last person leaves channel */
-#define CI_KEEPTOPIC 0x00000001
-/* Don't allow non-authorized users to be opped */
-#define CI_SECUREOPS 0x00000002
-/* Hide channel from ChanServ LIST command */
-#define CI_PRIVATE 0x00000004
-/* Topic can only be changed by SET TOPIC */
-#define CI_TOPICLOCK 0x00000008
-/* Those not allowed ops are kickbanned */
-#define CI_RESTRICTED 0x00000010
-/* Don't allow ChanServ and BotServ commands to do bad things to bigger levels */
-#define CI_PEACE 0x00000020
-/* Don't allow any privileges unless a user is IDENTIFY'd with NickServ */
-#define CI_SECURE 0x00000040
-/* Don't allow the channel to be registered or used */
-#define CI_FORBIDDEN 0x00000080
-/* Channel password is encrypted */
-#define CI_ENCRYPTEDPW 0x00000100
-/* Channel does not expire */
-#define CI_NO_EXPIRE 0x00000200
-/* Channel memo limit may not be changed */
-#define CI_MEMO_HARDMAX 0x00000400
-/* Send notice to channel on use of OP/DEOP */
-#define CI_OPNOTICE 0x00000800
-/* Stricter control of channel founder status */
-#define CI_SECUREFOUNDER 0x00001000
-/* Always sign kicks */
-#define CI_SIGNKICK 0x00002000
-/* Sign kicks if level is < than the one defined by the SIGNKICK level */
-#define CI_SIGNKICK_LEVEL 0x00004000
-/* Use the xOP lists */
-#define CI_XOP 0x00008000
-/* Channel is suspended */
-#define CI_SUSPENDED 0x00010000
-
-/* akick */
-#define AK_USED 0x0001
-#define AK_ISNICK 0x0002
-#define AK_STUCK 0x0004
-
-/* botflags */
-#define BI_PRIVATE 0x0001
-#define BI_CHANSERV 0x0002
-#define BI_BOTSERV 0x0004
-#define BI_HOSTSERV 0x0008
-#define BI_OPERSERV 0x0010
-#define BI_MEMOSERV 0x0020
-#define BI_NICKSERV 0x0040
-#define BI_GLOBAL 0x0080
-
-/* BotServ SET flags */
-#define BS_DONTKICKOPS 0x00000001
-#define BS_DONTKICKVOICES 0x00000002
-#define BS_FANTASY 0x00000004
-#define BS_SYMBIOSIS 0x00000008
-#define BS_GREET 0x00000010
-#define BS_NOBOT 0x00000020
-
-/* BotServ Kickers flags */
-#define BS_KICK_BOLDS 0x80000000
-#define BS_KICK_COLORS 0x40000000
-#define BS_KICK_REVERSES 0x20000000
-#define BS_KICK_UNDERLINES 0x10000000
-#define BS_KICK_BADWORDS 0x08000000
-#define BS_KICK_CAPS 0x04000000
-#define BS_KICK_FLOOD 0x02000000
-#define BS_KICK_REPEAT 0x01000000
-
-/* Indices for TTB (Times To Ban) */
-enum
-{
- TTB_BOLDS,
- TTB_COLORS,
- TTB_REVERSES,
- TTB_UNDERLINES,
- TTB_BADWORDS,
- TTB_CAPS,
- TTB_FLOOD,
- TTB_REPEAT,
- TTB_SIZE
-};
-
-enum
-{
- LANG_EN_US, /* United States English */
- LANG_JA_JIS, /* Japanese (JIS encoding) */
- LANG_JA_EUC, /* Japanese (EUC encoding) */
- LANG_JA_SJIS, /* Japanese (SJIS encoding) */
- LANG_ES, /* Spanish */
- LANG_PT, /* Portugese */
- LANG_FR, /* French */
- LANG_TR, /* Turkish */
- LANG_IT, /* Italian */
- LANG_DE, /* German */
- LANG_CAT, /* Catalan */
- LANG_GR, /* Greek */
- LANG_NL, /* Dutch */
- LANG_RU, /* Russian */
- LANG_HUN, /* Hungarian */
- LANG_PL /* Polish */
-};
-
-const std::string GetLanguageID(int id)
-{
- switch (id)
- {
- case LANG_EN_US:
- return "en_US";
- break;
- case LANG_JA_JIS:
- case LANG_JA_EUC:
- case LANG_JA_SJIS: // these seem to be unused
- return "en_US";
- break;
- case LANG_ES:
- return "es_ES";
- break;
- case LANG_PT:
- return "pt_PT";
- break;
- case LANG_FR:
- return "fr_FR";
- break;
- case LANG_TR:
- return "tr_TR";
- break;
- case LANG_IT:
- return "it_IT";
- break;
- case LANG_DE:
- return "de_DE";
- break;
- case LANG_CAT:
- return "ca_ES"; // yes, iso639 defines catalan as CA
- break;
- case LANG_GR:
- return "el_GR";
- break;
- case LANG_NL:
- return "nl_NL";
- break;
- case LANG_RU:
- return "ru_RU";
- break;
- case LANG_HUN:
- return "hu_HU";
- break;
- case LANG_PL:
- return "pl_PL";
- break;
- default:
- abort();
- }
-}
-
-/* Open a database file for reading and check for the version */
-dbFILE *open_db_read(const char *service, const char *filename, int version)
-{
- dbFILE *f;
- FILE *fp;
- int myversion;
-
- f = new dbFILE;
- if (!f)
- {
- printf("Can't allocate memory for %s database %s.\n", service, filename);
- exit(0);
- }
- strscpy(f->filename, filename, sizeof(f->filename));
- f->mode = 'r';
- fp = fopen(f->filename, "rb");
- if (!fp)
- {
- printf("Can't read %s database %s.\n", service, f->filename);
- //free(f);
- delete f;
- return NULL;
- }
- f->fp = fp;
- myversion = fgetc(fp) << 24 | fgetc(fp) << 16 | fgetc(fp) << 8 | fgetc(fp);
- if (feof(fp))
- {
- printf("Error reading version number on %s: End of file detected.\n", f->filename);
- exit(0);
- }
- else if (myversion < version)
- {
- printf("Unsuported database version (%d) on %s.\n", myversion, f->filename);
- exit(0);
- }
- return f;
-}
-
-/* Close it */
-void close_db(dbFILE *f)
-{
- fclose(f->fp);
- delete f;
-}
-
-int read_int16(int16 *ret, dbFILE *f)
-{
- int c1, c2;
-
- c1 = fgetc(f->fp);
- c2 = fgetc(f->fp);
- if (c1 == EOF || c2 == EOF)
- return -1;
- *ret = c1 << 8 | c2;
- return 0;
-}
-
-int read_uint16(uint16 *ret, dbFILE *f)
-{
- int c1, c2;
-
- c1 = fgetc(f->fp);
- c2 = fgetc(f->fp);
- if (c1 == EOF || c2 == EOF)
- return -1;
- *ret = c1 << 8 | c2;
- return 0;
-}
-
-int write_int16(uint16 val, dbFILE *f)
-{
- if (fputc((val >> 8) & 0xFF, f->fp) == EOF || fputc(val & 0xFF, f->fp) == EOF)
- return -1;
- return 0;
-}
-
-int read_int32(int32 *ret, dbFILE *f)
-{
- int c1, c2, c3, c4;
-
- c1 = fgetc(f->fp);
- c2 = fgetc(f->fp);
- c3 = fgetc(f->fp);
- c4 = fgetc(f->fp);
- if (c1 == EOF || c2 == EOF || c3 == EOF || c4 == EOF)
- return -1;
- *ret = c1 << 24 | c2 << 16 | c3 << 8 | c4;
- return 0;
-}
-
-int read_uint32(uint32 *ret, dbFILE *f)
-{
- int c1, c2, c3, c4;
-
- c1 = fgetc(f->fp);
- c2 = fgetc(f->fp);
- c3 = fgetc(f->fp);
- c4 = fgetc(f->fp);
- if (c1 == EOF || c2 == EOF || c3 == EOF || c4 == EOF)
- return -1;
- *ret = c1 << 24 | c2 << 16 | c3 << 8 | c4;
- return 0;
-}
-
-int write_int32(uint32 val, dbFILE *f)
-{
- if (fputc((val >> 24) & 0xFF, f->fp) == EOF)
- return -1;
- if (fputc((val >> 16) & 0xFF, f->fp) == EOF)
- return -1;
- if (fputc((val >> 8) & 0xFF, f->fp) == EOF)
- return -1;
- if (fputc((val) & 0xFF, f->fp) == EOF)
- return -1;
- return 0;
-}
-
-int read_ptr(void **ret, dbFILE *f)
-{
- int c;
-
- c = fgetc(f->fp);
- if (c == EOF)
- return -1;
- *ret = c ? reinterpret_cast<void *>(1) : reinterpret_cast<void *>(0);
- return 0;
-}
-
-int write_ptr(const void *ptr, dbFILE * f)
-{
- if (fputc(ptr ? 1 : 0, f->fp) == EOF)
- return -1;
- return 0;
-}
-
-int read_string(char **ret, dbFILE *f)
-{
- char *s;
- uint16 len;
-
- if (read_uint16(&len, f) < 0)
- return -1;
- if (len == 0)
- {
- *ret = NULL;
- return 0;
- }
- s = new char[len];
- if (len != fread(s, 1, len, f->fp))
- {
- delete [] s;
- return -1;
- }
- *ret = s;
- return 0;
-}
-
-int write_string(const char *s, dbFILE *f)
-{
- uint32 len;
-
- if (!s)
- return write_int16(0, f);
- len = strlen(s);
- if (len > 65534)
- len = 65534;
- if (write_int16(static_cast<uint16>(len + 1), f) < 0)
- return -1;
- if (len > 0 && fwrite(s, 1, len, f->fp) != len)
- return -1;
- if (fputc(0, f->fp) == EOF)
- return -1;
- return 0;
-}
-
-NickCore *findcore(const char *nick, int unused)
-{
- NickCore *nc;
-
- for (nc = nclists[HASH(nick)]; nc; nc = nc->next)
- if (!mystricmp(nc->display, nick) && ((nc->unused && unused) || (!nc->unused && !unused)))
- return nc;
-
- return NULL;
-}
-
-NickAlias *findnick(const char *nick)
-{
- NickAlias *na;
-
- for (na = nalists[HASH(nick)]; na; na = na->next)
- if (!mystricmp(na->nick, nick))
- return na;
-
- return NULL;
-}
-
-int write_file_version(dbFILE *f, uint32 version)
-{
- FILE *fp = f->fp;
- if (fputc(version >> 24 & 0xFF, fp) < 0 || fputc(version >> 16 & 0xFF, fp) < 0 || fputc(version >> 8 & 0xFF, fp) < 0 || fputc(version & 0xFF, fp) < 0)
- {
- printf("Error writing version number on %s.\n", f->filename);
- exit(0);
- }
- return 1;
-}
-
-/* strscpy: Copy at most len-1 characters from a string to a buffer, and
- * add a null terminator after the last character copied.
- */
-
-char *strscpy(char *d, const char *s, size_t len)
-{
- char *d_orig = d;
-
- if (!len)
- return d;
- while (--len && (*d++ = *s++));
- *d = '\0';
- return d_orig;
-}
-
-int mystricmp(const char *s1, const char *s2)
-{
- register int c;
-
- while ((c = tolower(*s1)) == tolower(*s2))
- {
- if (!c)
- return 0;
- ++s1;
- ++s2;
- }
- if (c < tolower(*s2))
- return -1;
- return 1;
-}
-
-int delnick(NickAlias *na, int donttouchthelist)
-{
- if (!donttouchthelist)
- {
- /* Remove us from the aliases list */
- if (na->next)
- na->next->prev = na->prev;
- if (na->prev)
- na->prev->next = na->next;
- else
- nalists[HASH(na->nick)] = na->next;
- }
-
- if (na->last_usermask)
- delete [] na->last_usermask;
- if (na->last_realname)
- delete [] na->last_realname;
- if (na->last_quit)
- delete [] na->last_quit;
- /* free() us */
- delete [] na->nick;
- delete na;
- return 1;
-}
-
-int delcore(NickCore *nc)
-{
- int i;
- /* Remove the core from the list */
- if (nc->next)
- nc->next->prev = nc->prev;
- if (nc->prev)
- nc->prev->next = nc->next;
- else
- nclists[HASH(nc->display)] = nc->next;
-
- delete [] nc->display;
- if (nc->email)
- delete [] nc->email;
- if (nc->greet)
- delete [] nc->greet;
- if (nc->url)
- delete [] nc->url;
- if (nc->access)
- {
- for (i = 0; i < nc->accesscount; ++i)
- if (nc->access[i])
- delete [] nc->access[i];
- delete [] nc->access;
- }
- if (nc->memos.memos)
- {
- for (i = 0; i < nc->memos.memocount; ++i)
- if (nc->memos.memos[i].text)
- delete [] nc->memos.memos[i].text;
- delete [] nc->memos.memos;
- }
- delete nc;
- return 1;
-}
-
-ChannelInfo *cs_findchan(const char *chan)
-{
- ChannelInfo *ci;
- for (ci = chanlists[tolower(chan[1])]; ci; ci = ci->next)
- if (!mystricmp(ci->name, chan))
- return ci;
- return NULL;
-}
-
-void alpha_insert_chan(ChannelInfo *ci)
-{
- ChannelInfo *ptr, *prev;
- char *chan = ci->name;
-
- for (prev = NULL, ptr = chanlists[tolower(chan[1])]; ptr && mystricmp(ptr->name, chan) < 0; prev = ptr, ptr = ptr->next);
- ci->prev = prev;
- ci->next = ptr;
- if (!prev)
- chanlists[tolower(chan[1])] = ci;
- else
- prev->next = ci;
- if (ptr)
- ptr->prev = ci;
-}
-
-HostCore *findHostCore(char *nick)
-{
- for (HostCore *hc = head; hc; hc = hc->next)
- if (nick && hc->nick && !mystricmp(hc->nick, nick))
- return hc;
- return NULL;
-}
-
-static char *int_to_base64(long);
-static long base64_to_int(char *);
-
-const char *base64enc(long i)
-{
- if (i < 0)
- return "0";
- return int_to_base64(i);
-}
-
-long base64dec(char *b64)
-{
- if (b64)
- return base64_to_int(b64);
- else
- return 0;
-}
-
-std::string Hex(const std::string &data)
-{
- const char hextable[] = "0123456789abcdef";
-
- size_t l = data.length();
- std::string rv;
- for (size_t i = 0; i < l; ++i)
- {
- unsigned char c = data[i];
- rv += hextable[c >> 4];
- rv += hextable[c & 0xF];
- }
- return rv;
-}
-
-static const char Base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-static const char Pad64 = '=';
-
-/* (From RFC1521 and draft-ietf-dnssec-secext-03.txt)
- The following encoding technique is taken from RFC 1521 by Borenstein
- and Freed. It is reproduced here in a slightly edited form for
- convenience.
-
- A 65-character subset of US-ASCII is used, enabling 6 bits to be
- represented per printable character. (The extra 65th character, "=",
- is used to signify a special processing function.)
-
- The encoding process represents 24-bit groups of input bits as output
- strings of 4 encoded characters. Proceeding from left to right, a
- 24-bit input group is formed by concatenating 3 8-bit input groups.
- These 24 bits are then treated as 4 concatenated 6-bit groups, each
- of which is translated into a single digit in the base64 alphabet.
-
- Each 6-bit group is used as an index into an array of 64 printable
- characters. The character referenced by the index is placed in the
- output string.
-
- Table 1: The Base64 Alphabet
-
- Value Encoding Value Encoding Value Encoding Value Encoding
- 0 A 17 R 34 i 51 z
- 1 B 18 S 35 j 52 0
- 2 C 19 T 36 k 53 1
- 3 D 20 U 37 l 54 2
- 4 E 21 V 38 m 55 3
- 5 F 22 W 39 n 56 4
- 6 G 23 X 40 o 57 5
- 7 H 24 Y 41 p 58 6
- 8 I 25 Z 42 q 59 7
- 9 J 26 a 43 r 60 8
- 10 K 27 b 44 s 61 9
- 11 L 28 c 45 t 62 +
- 12 M 29 d 46 u 63 /
- 13 N 30 e 47 v
- 14 O 31 f 48 w (pad) =
- 15 P 32 g 49 x
- 16 Q 33 h 50 y
-
- Special processing is performed if fewer than 24 bits are available
- at the end of the data being encoded. A full encoding quantum is
- always completed at the end of a quantity. When fewer than 24 input
- bits are available in an input group, zero bits are added (on the
- right) to form an integral number of 6-bit groups. Padding at the
- end of the data is performed using the '=' character.
-
- Since all base64 input is an integral number of octets, only the
- -------------------------------------------------
- following cases can arise:
-
- (1) the final quantum of encoding input is an integral
- multiple of 24 bits; here, the final unit of encoded
- output will be an integral multiple of 4 characters
- with no "=" padding,
- (2) the final quantum of encoding input is exactly 8 bits;
- here, the final unit of encoded output will be two
- characters followed by two "=" padding characters, or
- (3) the final quantum of encoding input is exactly 16 bits;
- here, the final unit of encoded output will be three
- characters followed by one "=" padding character.
- */
-
-void b64_encode(const std::string &src, std::string &target)
-{
- size_t src_pos = 0, src_len = src.length();
- unsigned char input[3];
-
- target.clear();
-
- while (src_len - src_pos > 2)
- {
- input[0] = src[src_pos++];
- input[1] = src[src_pos++];
- input[2] = src[src_pos++];
-
- target += Base64[input[0] >> 2];
- target += Base64[((input[0] & 0x03) << 4) + (input[1] >> 4)];
- target += Base64[((input[1] & 0x0f) << 2) + (input[2] >> 6)];
- target += Base64[input[2] & 0x3f];
- }
-
- /* Now we worry about padding */
- if (src_pos != src_len)
- {
- input[0] = input[1] = input[2] = 0;
- for (size_t i = 0; i < src_len - src_pos; ++i)
- input[i] = src[src_pos + i];
-
- target += Base64[input[0] >> 2];
- target += Base64[((input[0] & 0x03) << 4) + (input[1] >> 4)];
- if (src_pos == src_len - 1)
- target += Pad64;
- else
- target += Base64[((input[1] & 0x0f) << 2) + (input[2] >> 6)];
- target += Pad64;
- }
-}
-
-
-/* ':' and '#' and '&' and '+' and '@' must never be in this table. */
-/* these tables must NEVER CHANGE! >) */
-char int6_to_base64_map[] = {
- '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',
- 'E', 'F',
- 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
- 'U', 'V',
- 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
- 'k', 'l',
- 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
- '{', '}'
-};
-
-char base64_to_int6_map[] = {
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
- -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
- 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,
- -1, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
- 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, -1, 63, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
- -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
-};
-
-static char *int_to_base64(long val)
-{
- /* 32/6 == max 6 bytes for representation,
- * +1 for the null, +1 for byte boundaries
- */
- static char base64buf[8];
- long i = 7;
-
- base64buf[i] = '\0';
-
- /* Temporary debugging code.. remove before 2038 ;p.
- * This might happen in case of 64bit longs (opteron/ia64),
- * if the value is then too large it can easily lead to
- * a buffer underflow and thus to a crash. -- Syzop
- */
- if (val > 2147483647L)
- abort();
-
- do
- {
- base64buf[--i] = int6_to_base64_map[val & 63];
- }
- while (val >>= 6);
-
- return base64buf + i;
-}
-
-static long base64_to_int(char *b64)
-{
- int v = base64_to_int6_map[static_cast<unsigned char>(*b64++)];
-
- if (!b64)
- return 0;
-
- while (*b64)
- {
- v <<= 6;
- v += base64_to_int6_map[static_cast<unsigned char>(*b64++)];
- }
-
- return v;
-}
-
-#endif // DB_CONVERT_H