Anope IRC Services  Version 1.8
Data Structures | Macros | Typedefs | Functions | Variables
db-merger.c File Reference
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <fcntl.h>
#include <ctype.h>
#include <time.h>
#include <unistd.h>
Include dependency graph for db-merger.c:

Go to the source code of this file.

Data Structures

struct  memo_
 
struct  dbFILE_
 
struct  MemoInfo
 
struct  ChanAccess
 
struct  AutoKick
 
struct  nickalias_
 
struct  nickcore_
 
struct  chaninfo_
 
struct  botinfo_
 
struct  badword_
 
struct  hostcore_
 

Macros

#define NICK_DB_1   "nick1.db"
 
#define NICK_DB_2   "nick2.db"
 
#define NICK_DB_NEW   "nick.db"
 
#define CHAN_DB_1   "chan1.db"
 
#define CHAN_DB_2   "chan2.db"
 
#define CHAN_DB_NEW   "chan.db"
 
#define BOT_DB_1   "bot1.db"
 
#define BOT_DB_2   "bot2.db"
 
#define BOT_DB_NEW   "bot.db"
 
#define HOST_DB_1   "hosts1.db"
 
#define HOST_DB_2   "hosts2.db"
 
#define HOST_DB_NEW   "hosts.db"
 
#define C_LBLUE   "\033[1;34m"
 
#define C_NONE   "\033[m"
 
#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)
 
#define READ(x)
 

Typedefs

typedef int16_t int16
 
typedef u_int16_t uint16
 
typedef int32_t int32
 
typedef u_int32_t uint32
 
typedef struct memo_ Memo
 
typedef struct dbFILE_ dbFILE
 
typedef struct nickalias_ NickAlias
 
typedef struct nickcore_ NickCore
 
typedef struct chaninfo_ ChannelInfo
 
typedef struct botinfo_ BotInfo
 
typedef struct badword_ BadWord
 
typedef struct hostcore_ HostCore
 

Functions

dbFILEopen_db_write (const char *service, const char *filename, int version)
 
dbFILEopen_db_read (const char *service, const char *filename, int version)
 
NickCorefindcore (const char *nick, int version)
 
NickAliasfindnick (const char *nick)
 
BotInfofindbot (char *nick)
 
ChannelInfocs_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 insert_bot (BotInfo *bi)
 
void close_db (dbFILE *f)
 
int main (int argc, char *argv[])
 

Variables

ChannelInfochanlists [256]
 
NickAliasnalists [1024]
 
NickCorenclists [1024]
 
BotInfobotlists [256]
 
int preferfirst = 0
 
int prefersecond = 0
 
int preferoldest = 0
 
int prefernewest = 0
 
int nonick = 0
 
int nochan = 0
 
int nobot = 0
 
int nohost = 0
 

Macro Definition Documentation

#define BOT_DB_1   "bot1.db"

Definition at line 81 of file db-merger.c.

Referenced by main().

#define BOT_DB_2   "bot2.db"

Definition at line 82 of file db-merger.c.

Referenced by main().

#define BOT_DB_NEW   "bot.db"

Definition at line 83 of file db-merger.c.

Referenced by main().

#define C_LBLUE   "\033[1;34m"

Definition at line 92 of file db-merger.c.

Referenced by main().

#define C_NONE   "\033[m"

Definition at line 93 of file db-merger.c.

Referenced by main().

#define CHAN_DB_1   "chan1.db"

Definition at line 77 of file db-merger.c.

Referenced by main().

#define CHAN_DB_2   "chan2.db"

Definition at line 78 of file db-merger.c.

Referenced by main().

#define CHAN_DB_NEW   "chan.db"

Definition at line 79 of file db-merger.c.

Referenced by main().

#define getc_db (   f)    (fgetc((f)->fp))

Definition at line 99 of file db-merger.c.

Referenced by main().

#define HASH (   nick)    ((tolower((nick)[0])&31)<<5 | (tolower((nick)[1])&31))

Definition at line 100 of file db-merger.c.

Referenced by delcore(), delnick(), findcore(), findnick(), and main().

#define HASH2 (   chan)    ((chan)[1] ? ((chan)[1]&31)<<5 | ((chan)[2]&31) : 0)

Definition at line 101 of file db-merger.c.

#define HOST_DB_1   "hosts1.db"

Definition at line 85 of file db-merger.c.

Referenced by main().

#define HOST_DB_2   "hosts2.db"

Definition at line 86 of file db-merger.c.

Referenced by main().

#define HOST_DB_NEW   "hosts.db"

Definition at line 87 of file db-merger.c.

Referenced by main().

#define NICK_DB_1   "nick1.db"

Definition at line 73 of file db-merger.c.

Referenced by main().

#define NICK_DB_2   "nick2.db"

Definition at line 74 of file db-merger.c.

Referenced by main().

#define NICK_DB_NEW   "nick.db"

Definition at line 75 of file db-merger.c.

Referenced by main().

#define READ (   x)
Value:
do { \
if ((x) < 0) { \
printf("Error, the database is broken, trying to continue... no guarantee.\n"); \
exit(0); \
} \
} while (0)

Definition at line 113 of file db-merger.c.

Referenced by main().

#define read_buffer (   buf,
 
)    (read_db((f),(buf),sizeof(buf)) == sizeof(buf))

Definition at line 102 of file db-merger.c.

Referenced by main().

#define read_db (   f,
  buf,
  len 
)    (fread((buf),1,(len),(f)->fp))

Definition at line 104 of file db-merger.c.

#define read_int8 (   ret,
 
)    ((*(ret)=fgetc((f)->fp))==EOF ? -1 : 0)

Definition at line 106 of file db-merger.c.

#define SAFE (   x)
Value:
do { \
if ((x) < 0) { \
printf("Error, the database is broken, trying to continue... no guarantee.\n"); \
} \
} while (0)

Definition at line 108 of file db-merger.c.

Referenced by main().

#define write_buffer (   buf,
 
)    (write_db((f),(buf),sizeof(buf)) == sizeof(buf))

Definition at line 103 of file db-merger.c.

Referenced by main().

#define write_db (   f,
  buf,
  len 
)    (fwrite((buf),1,(len),(f)->fp))

Definition at line 105 of file db-merger.c.

#define write_int8 (   val,
 
)    (fputc((val),(f)->fp)==EOF ? -1 : 0)

Definition at line 107 of file db-merger.c.

Referenced by main().

Typedef Documentation

typedef struct badword_ BadWord

Definition at line 130 of file db-merger.c.

typedef struct botinfo_ BotInfo

Definition at line 129 of file db-merger.c.

typedef struct chaninfo_ ChannelInfo

Definition at line 128 of file db-merger.c.

typedef struct dbFILE_ dbFILE

Definition at line 125 of file db-merger.c.

typedef struct hostcore_ HostCore

Definition at line 131 of file db-merger.c.

typedef int16_t int16

Definition at line 120 of file db-merger.c.

typedef int32_t int32

Definition at line 122 of file db-merger.c.

typedef struct memo_ Memo

Definition at line 124 of file db-merger.c.

typedef struct nickalias_ NickAlias

Definition at line 126 of file db-merger.c.

typedef struct nickcore_ NickCore

Definition at line 127 of file db-merger.c.

typedef u_int16_t uint16

Definition at line 121 of file db-merger.c.

typedef u_int32_t uint32

Definition at line 123 of file db-merger.c.

Function Documentation

void alpha_insert_chan ( ChannelInfo ci)

Definition at line 2010 of file db-merger.c.

References mystricmp(), chaninfo_::name, chaninfo_::next, chaninfo_::prev, and tolower.

Referenced by main().

void close_db ( dbFILE f)

Close a database file. If the file was opened for write, remove the backup we (may have) created earlier.

Parameters
dbFilestruct
Returns
void

Definition at line 1706 of file db-merger.c.

References dbFILE_::fp.

Referenced by main().

ChannelInfo* cs_findchan ( const char *  chan)

Definition at line 2000 of file db-merger.c.

References mystricmp(), chaninfo_::name, chaninfo_::next, and tolower.

Referenced by main().

int delcore ( NickCore nc)
int delnick ( NickAlias na,
int  donttouchthelist 
)
BotInfo* findbot ( char *  nick)
NickCore * findcore ( const char *  nick,
int  version 
)

Definition at line 1844 of file db-merger.c.

References nickcore_::display, HASH, mystricmp(), nickcore_::next, and nickcore_::unused.

Referenced by main().

NickAlias* findnick ( const char *  nick)
void insert_bot ( BotInfo bi)

Definition at line 1972 of file db-merger.c.

References mystricmp(), botinfo_::next, botinfo_::nick, botinfo_::prev, and tolower.

Referenced by change_bot_nick(), and main().

int main ( int  argc,
char *  argv[] 
)

Definition at line 305 of file db-merger.c.

References nickcore_::access, chaninfo_::access, nickcore_::accesscount, chaninfo_::accesscount, AutoKick::addtime, chaninfo_::akick, chaninfo_::akickcount, nickcore_::aliascount, alpha_insert_chan(), chaninfo_::badwords, chaninfo_::bantype, chaninfo_::bi, BOT_DB_1, BOT_DB_2, BOT_DB_NEW, chaninfo_::botflags, chaninfo_::bwcount, c, C_LBLUE, C_NONE, chaninfo_::capsmin, chaninfo_::capspercent, CHAN_DB_1, CHAN_DB_2, CHAN_DB_NEW, botinfo_::chancount, nickcore_::channelcount, nickcore_::channelmax, close_db(), botinfo_::created, AutoKick::creator, hostcore_::creator, cs_findchan(), delcore(), delnick(), chaninfo_::desc, nickcore_::display, nickcore_::email, chaninfo_::email, chaninfo_::entry_message, findbot(), findcore(), findnick(), memo_::flags, nickcore_::flags, botinfo_::flags, AutoKick::flags, chaninfo_::flags, chaninfo_::floodlines, chaninfo_::floodsecs, chaninfo_::forbidby, chaninfo_::forbidreason, chaninfo_::founder, chaninfo_::founderpass, getc_db, nickcore_::greet, HASH, botinfo_::host, HOST_DB_1, HOST_DB_2, HOST_DB_NEW, nickcore_::icq, ChanAccess::in_use, badword_::in_use, insert_bot(), nickcore_::language, hostcore_::last, nickalias_::last_quit, nickalias_::last_realname, nickalias_::last_seen, ChanAccess::last_seen, chaninfo_::last_topic, chaninfo_::last_topic_setter, chaninfo_::last_topic_time, chaninfo_::last_used, nickalias_::last_usermask, ChanAccess::level, chaninfo_::levels, AutoKick::mask, MemoInfo::memocount, MemoInfo::memomax, MemoInfo::memos, nickcore_::memos, chaninfo_::memos, chaninfo_::mlock_flood, chaninfo_::mlock_key, chaninfo_::mlock_limit, chaninfo_::mlock_off, chaninfo_::mlock_on, chaninfo_::mlock_redirect, mystricmp(), chaninfo_::name, nickalias_::nc, ChanAccess::nc, AutoKick::nc, nickalias_::next, nickcore_::next, botinfo_::next, chaninfo_::next, hostcore_::next, nickalias_::nick, botinfo_::nick, hostcore_::nick, NICK_DB_1, NICK_DB_2, NICK_DB_NEW, nobot, nochan, nohost, nonick, memo_::number, open_db_read(), open_db_write(), nickcore_::pass, preferfirst, prefernewest, preferoldest, prefersecond, nickalias_::prev, nickcore_::prev, botinfo_::prev, chaninfo_::prev, READ, read_buffer, read_int16(), read_int32(), read_string(), read_uint16(), read_uint32(), botinfo_::real, AutoKick::reason, chaninfo_::repeattimes, SAFE, memo_::sender, nickalias_::status, strdup(), chaninfo_::successor, memo_::text, memo_::time, hostcore_::time, nickalias_::time_registered, chaninfo_::time_registered, tolower, chaninfo_::ttb, badword_::type, AutoKick::u, nickcore_::unused, nickcore_::url, chaninfo_::url, botinfo_::user, hostcore_::vHost, hostcore_::vIdent, badword_::word, write_buffer, write_int16(), write_int32(), write_int8, and write_string().

int mystricmp ( const char *  s1,
const char *  s2 
)

Definition at line 1897 of file db-merger.c.

References c, and tolower.

Referenced by alpha_insert_chan(), cs_findchan(), findbot(), findcore(), findnick(), insert_bot(), and main().

dbFILE * open_db_read ( const char *  service,
const char *  filename,
int  version 
)

Definition at line 1633 of file db-merger.c.

References dbFILE_::filename, dbFILE_::fp, dbFILE_::mode, and strscpy().

Referenced by main().

dbFILE * open_db_write ( const char *  service,
const char *  filename,
int  version 
)

Definition at line 1665 of file db-merger.c.

References dbFILE_::filename, dbFILE_::fp, dbFILE_::mode, strscpy(), and write_file_version().

Referenced by main().

int read_int16 ( int16 ret,
dbFILE f 
)

Definition at line 1712 of file db-merger.c.

References dbFILE_::fp.

Referenced by main().

int read_int32 ( int32 ret,
dbFILE f 
)

Definition at line 1745 of file db-merger.c.

References dbFILE_::fp.

Referenced by main().

int read_ptr ( void **  ret,
dbFILE f 
)

Read Pointer

Parameters
retpointer to read
dbFilestruct
Returns
-1 on error, 0 otherwise.

Definition at line 1787 of file db-merger.c.

References c, and dbFILE_::fp.

int read_string ( char **  ret,
dbFILE f 
)

Read String

Parameters
retstring
dbFilestruct
Returns
-1 on error, 0 otherwise.

Definition at line 1806 of file db-merger.c.

References dbFILE_::fp, and read_uint16().

Referenced by main().

int read_uint16 ( uint16 ret,
dbFILE f 
)

Definition at line 1724 of file db-merger.c.

References dbFILE_::fp.

Referenced by main(), and read_string().

int read_uint32 ( uint32 ret,
dbFILE f 
)

Definition at line 1759 of file db-merger.c.

References dbFILE_::fp.

Referenced by main().

char* strscpy ( char *  d,
const char *  s,
size_t  len 
)

strscpy: Copy at most len-1 characters from a string to a buffer, and add a null terminator after the last character copied.

Parameters
dBuffer to copy into
sData to copy int
lenLength of data
Returns
updated buffer

Definition at line 1886 of file db-merger.c.

Referenced by open_db_read(), and open_db_write().

int write_file_version ( dbFILE f,
uint32  version 
)

Write the current version number to the file.

Parameters
fdbFile Struct Member
Returns
0 on error, 1 on success.

Definition at line 1869 of file db-merger.c.

References dbFILE_::filename, and dbFILE_::fp.

Referenced by open_db_write().

int write_int16 ( uint16  val,
dbFILE f 
)

Write a 16bit integer

Parameters
ret16bit integer to write
dbFilestruct
Returns
-1 on error, 0 otherwise.

Definition at line 1737 of file db-merger.c.

References dbFILE_::fp.

Referenced by main(), and write_string().

int write_int32 ( uint32  val,
dbFILE f 
)

Write a unsigned 32bit integer

Parameters
retunsigned 32bit integer to write
dbFilestruct
Returns
-1 on error, 0 otherwise.

Definition at line 1773 of file db-merger.c.

References dbFILE_::fp.

Referenced by main().

int write_ptr ( const void *  ptr,
dbFILE f 
)

Write Pointer

Parameters
retpointer to write
dbFilestruct
Returns
-1 on error, 0 otherwise.

Definition at line 1798 of file db-merger.c.

References dbFILE_::fp.

int write_string ( const char *  s,
dbFILE f 
)

Write String

Parameters
retstring
dbFilestruct
Returns
-1 on error, 0 otherwise.

Definition at line 1826 of file db-merger.c.

References dbFILE_::fp, and write_int16().

Referenced by main().

Variable Documentation

BotInfo* botlists[256]

Definition at line 300 of file db-merger.c.

ChannelInfo* chanlists[256]

Definition at line 297 of file db-merger.c.

NickAlias* nalists[1024]

Definition at line 298 of file db-merger.c.

NickCore* nclists[1024]

Definition at line 299 of file db-merger.c.

int nobot = 0

Definition at line 303 of file db-merger.c.

Referenced by main().

int nochan = 0

Definition at line 303 of file db-merger.c.

Referenced by main().

int nohost = 0

Definition at line 303 of file db-merger.c.

Referenced by main().

int nonick = 0

Definition at line 303 of file db-merger.c.

Referenced by main().

int preferfirst = 0

Definition at line 302 of file db-merger.c.

Referenced by main().

int prefernewest = 0

Definition at line 302 of file db-merger.c.

Referenced by main().

int preferoldest = 0

Definition at line 302 of file db-merger.c.

Referenced by main().

int prefersecond = 0

Definition at line 302 of file db-merger.c.

Referenced by main().