diff options
| author | rburchell <rburchell@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-11-14 20:57:20 +0000 |
|---|---|---|
| committer | rburchell <rburchell@5417fbe8-f217-4b02-8779-1006273d7864> | 2008-11-14 20:57:20 +0000 |
| commit | 6c55e0a529c7f1216ff6f63a4fc77ea06a2a3a38 (patch) | |
| tree | 91b0841faf23087ebe0c74dd4269d181a383f1e7 /src/tools/db-merger.c | |
| parent | 069409cd99cf78ab8bf87a1fe69a833576414fd3 (diff) | |
Insane commit of doom: s/ \t/g
git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1681 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src/tools/db-merger.c')
| -rw-r--r-- | src/tools/db-merger.c | 3414 |
1 files changed, 1707 insertions, 1707 deletions
diff --git a/src/tools/db-merger.c b/src/tools/db-merger.c index a80508af5..dae44d74b 100644 --- a/src/tools/db-merger.c +++ b/src/tools/db-merger.c @@ -18,7 +18,7 @@ * that includes chanserv, nickserv, botserv and memoserv databases. * * - Certus - * February 11, 2005 + * February 11, 2005 * * * 0.2 beta: @@ -26,21 +26,21 @@ * to fix your broken nick dbs. * * - Certus - * August 04, 2005 + * August 04, 2005 * * * 0.3 beta: * Fixed win32 stuff. Merging should now work fine under windows. * * - Certus - * July 20, 2006 + * July 20, 2006 * * * 0.4 beta: * Fixed some compiler warnings about signed/unsigned ints. * * - Certus - * August 8, 2006 + * August 8, 2006 */ @@ -82,20 +82,20 @@ /* CONFIGURATION BLOCK */ -#define NICK_DB_1 "nick1.db" -#define NICK_DB_2 "nick2.db" +#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_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_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_1 "hosts1.db" +#define HOST_DB_2 "hosts2.db" #define HOST_DB_NEW "hosts.db" /* END OF CONFIGURATION BLOCK */ @@ -118,15 +118,15 @@ #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) do { \ - if ((x) < 0) { \ + if ((x) < 0) { \ printf("Error, the database is broken, trying to continue... no guarantee.\n"); \ - } \ + } \ } while (0) #define READ(x) do { \ - if ((x) < 0) { \ - printf("Error, the database is broken, trying to continue... no guarantee.\n"); \ - exit(0); \ - } \ + if ((x) < 0) { \ + printf("Error, the database is broken, trying to continue... no guarantee.\n"); \ + exit(0); \ + } \ } while (0) typedef int16_t int16; @@ -143,126 +143,126 @@ typedef struct badword_ BadWord; typedef struct hostcore_ HostCore; 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; + 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 */ + int mode; /* 'r' for reading, 'w' for writing */ + FILE *fp; /* The normal file descriptor */ + char filename[1024]; /* Name of the database file */ }; typedef struct { - int16 memocount; /* Current # of memos */ - int16 memomax; /* Max # of memos one can hold*/ - Memo *memos; /* Pointer to original memos */ + int16 memocount; /* Current # of memos */ + int16 memomax; /* Max # of memos one can hold*/ + Memo *memos; /* Pointer to original memos */ } MemoInfo; typedef struct { - 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; + 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; } ChanAccess; typedef struct { - int16 in_use; /* Always 0 if not in use */ - int16 is_nick; /* 1 if a regged nickname, 0 if a nick!user@host mask */ + 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 */ + 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; + } u; + char *reason; + char *creator; + time_t addtime; } AutoKick; struct nickalias_ { - NickAlias *next, *prev; - char *nick; /* Nickname */ - char *last_quit; /* Last quit message */ - char *last_realname; /* Last realname */ - char *last_usermask; /* Last usermask */ - 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 */ + NickAlias *next, *prev; + char *nick; /* Nickname */ + char *last_quit; /* Last quit message */ + char *last_realname; /* Last realname */ + char *last_usermask; /* Last usermask */ + 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 */ }; 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 */ + 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 chaninfo_ { - 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 */ + 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 botinfo_ { BotInfo *next, *prev; - char *nick; /* Nickname of the bot */ - char *user; /* Its user name */ - char *host; /* Its hostname */ - char *real; /* Its real name */ - int16 flags; /* Bot flags */ - time_t created; /* Birth date */ - int16 chancount; /* Number of channels that use the bot. */ + char *nick; /* Nickname of the bot */ + char *user; /* Its user name */ + char *host; /* Its hostname */ + char *real; /* Its real name */ + int16 flags; /* Bot flags */ + time_t created; /* Birth date */ + int16 chancount; /* Number of channels that use the bot. */ }; struct badword_ { @@ -272,12 +272,12 @@ struct badword_ { }; struct hostcore_ { - HostCore *next, *last; - char *nick; /* Owner of the vHost */ - char *vIdent; /* vIdent for the user */ - char *vHost; /* Vhost for this user */ - char *creator; /* Oper Nick of the oper who set the vhost */ - time_t time; /* Date/Time vHost was set */ + HostCore *next, *last; + char *nick; /* Owner of the vHost */ + char *vIdent; /* vIdent for the user */ + char *vHost; /* Vhost for this user */ + char *creator; /* Oper Nick of the oper who set the vhost */ + time_t time; /* Date/Time vHost was set */ }; dbFILE *open_db_write(const char *service, const char *filename, int version); @@ -315,1729 +315,1729 @@ int nonick = 0, nochan = 0, nobot = 0, nohost = 0; int main(int argc, char *argv[]) { - dbFILE *f; - int i; - NickCore *nc, *ncnext; - HostCore *firsthc = NULL; - - printf("\n"C_LBLUE"DB Merger v0.4 beta for Anope IRC Services by Certus"C_NONE"\n\n"); - - if (argc >= 2) { - if (!mystricmp(argv[1], "--PREFEROLDEST")) { - printf("Preferring oldest database entries on collision.\n"); - preferoldest = 1; - } else if (!mystricmp(argv[1], "--PREFERFIRST")) { - printf("Preferring first database's entries on collision .\n"); - preferfirst = 1; - } else if (!mystricmp(argv[1], "--PREFERSECOND")) { - printf("Preferring second database's entries on collision.\n"); - prefersecond = 1; - } else if (!mystricmp(argv[1], "--PREFERNEWEST")) { - printf("Preferring newest database entries on collision.\n"); - prefernewest = 1; - } - } - - /* Section I: Nicks */ - /* Ia: First database */ - if ((f = open_db_read("NickServ", NICK_DB_1, 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 %s.\n", NICK_DB_1); - exit(0); - } - - nc = (NickCore *)calloc(1, sizeof(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; - access = (char **)calloc(sizeof(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; - memos = (Memo *)calloc(sizeof(Memo) * nc->memos.memocount, 1); - 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 %s.\n", NICK_DB_1); - exit(0); - } - - na = (NickAlias *)calloc(1, sizeof(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); - - *nalast = na; - nalast = &na->next; - na->prev = naprev; - naprev = na; - } /* getc_db() */ - *nalast = NULL; - } /* for() loop */ - close_db(f); /* End of section Ia */ - } else - nonick = 1; - - /* Ib: Second database */ - if (!nonick) { - if ((f = open_db_read("NickServ", NICK_DB_2, 14))) { - - NickAlias *na, *naptr; - NickCore *nc; - int16 tmp16; - int32 tmp32; - int i, j, index, c; - - /* Nick cores */ - for (i = 0; i < 1024; i++) { - - while ((c = getc_db(f)) == 1) { - if (c != 1) { - printf("Invalid format in %s.\n", NICK_DB_2); - exit(0); - } - - nc = (NickCore *)calloc(1, sizeof(NickCore)); - READ(read_string(&nc->display, f)); - READ(read_buffer(nc->pass, f)); - READ(read_string(&nc->email, f)); - - naptr = findnick(nc->display); - if (naptr) - nc->unused = 1; - else - nc->unused = 0; - - nc->aliascount = 0; - - index = HASH(nc->display); - nc->prev = NULL; - nc->next = nclists[index]; - if (nc->next) - nc->next->prev = nc; - nclists[index] = nc; - - 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; - access = (char **)calloc(sizeof(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; - memos = (Memo *)calloc(sizeof(Memo) * nc->memos.memocount, 1); - 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() */ - } /* for() loop */ - - /* Nick aliases */ - for (i = 0; i < 1024; i++) { - char *s = NULL; - NickAlias *ptr, *prev, *naptr; - - while ((c = getc_db(f)) == 1) { - if (c != 1) { - printf("Invalid format in %s.\n", NICK_DB_1); - exit(0); - } - - na = (NickAlias *)calloc(1, sizeof(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)); - - naptr = findnick(na->nick); - if (naptr) { /* COLLISION! na = collision #1 (na->nc doesn't exist yet), naptr = collision #2 (naptr->nc exists) */ - char input[1024]; - NickCore *ncptr = findcore(na->nick, 1); /* Find core for #1, ncptr MUST exist since we've read all cores, if it doesn't eixst, we have a malformed db */; - - if (!ncptr) { /* malformed */ - printf("\n\n WARNING! Malformed database. No nickcore for nick %s, droping it.\n\n\n", na->nick); - delnick(na, 1); - } else { /* not malformed */ - if (!preferoldest && !preferfirst && !prefersecond && !prefernewest) { - printf("Nick collision for nick %s:\n\n", na->nick); - printf("Group 1: %s (%s)\n", ncptr->display, ncptr->email); - printf("Time registered: %s\n", ctime(&na->time_registered)); - printf("Group 2: %s (%s)\n", naptr->nc->display, naptr->nc->email); - printf("Time registered: %s\n", ctime(&naptr->time_registered)); - printf("What group do you want to keep? Enter the related group number \"1\" or \"2\".\n"); - } - - if (preferoldest) { - input[0] = (na->time_registered > naptr->time_registered) ? '1' : '2'; - } else if (prefernewest) { - input[0] = (na->time_registered > naptr->time_registered) ? '2' : '1'; - } else if (preferfirst) { - input[0] = '2'; - } else if (prefersecond) { - input[0] = '1'; - } else { - waiting_for_input: - scanf("%s", input); - } - if (input[0] == '1') { /* get alias #2 out of the list, then free() it, then add #1 to the list */ - printf("Deleting nick alias %s (#2).\n", naptr->nick); - naptr->nc->aliascount--; /* tell the core it has one alias less */ - delnick(naptr, 0); /* removes the alias from the list and free()s it */ - na->nc = ncptr; - na->nc->aliascount++; - index = HASH(na->nick); - for (prev = NULL, ptr = nalists[index]; ptr && mystricmp(ptr->nick, na->nick) < 0; prev = ptr, ptr = ptr->next); - na->prev = prev; - na->next = ptr; - if (!prev) - nalists[index] = na; - else - prev->next = na; - if (ptr) - ptr->prev = na; - } else if (input[0] == '2') { /* free() #1 alias */ - printf("Deleting nick alias %s (#1).\n", na->nick); - delnick(na, 1); /* free()s the alias without touching the list since na isn't in the list */ - } else { - printf("Invalid number, give us a valid one (1 or 2).\n"); - goto waiting_for_input; - } - } /* not malformed */ - } else { /* No collision, add the core pointer and put the alias in the list */ - na->nc = findcore(s, 0); - if (!na->nc) { - printf("\n\n WARNING! Malformed database. No nickcore for nick %s, droping it.\n\n\n", na->nick); - delnick(na, 1); - } else { - na->nc->aliascount++; - index = HASH(na->nick); - for (prev = NULL, ptr = nalists[index]; ptr && mystricmp(ptr->nick, na->nick) < 0; prev = ptr, ptr = ptr->next); - na->prev = prev; - na->next = ptr; - if (!prev) - nalists[index] = na; - else - prev->next = na; - if (ptr) - ptr->prev = na; - } - } - free(s); - } /* getc_db() */ - } /* for() loop */ - close_db(f); /* End of section Ib */ - } else - nonick = 1; - } - - /* CLEAN THE CORES */ - - for (i = 0; i < 1024; i++) { - for (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); - } - } - } - - /* Ic: Saving */ - if (!nonick) { - if ((f = open_db_write("NickServ", NICK_DB_NEW, 14))) { - - NickAlias *na; - NickCore *nc; - char **access; - Memo *memos; - int i, j; - - /* Nick cores */ - for (i = 0; i < 1024; i++) { - for (nc = nclists[i]; nc; nc = nc->next) { - SAFE(write_int8(1, f)); - SAFE(write_string(nc->display, f)); - SAFE(write_buffer(nc->pass, f)); - SAFE(write_string(nc->email, f)); - SAFE(write_string(nc->greet, f)); - SAFE(write_int32(nc->icq, f)); - SAFE(write_string(nc->url, f)); - SAFE(write_int32(nc->flags, f)); - SAFE(write_int16(nc->language, f)); - SAFE(write_int16(nc->accesscount, f)); - for (j = 0, access = nc->access; j < nc->accesscount; j++, access++) - SAFE(write_string(*access, f)); - - SAFE(write_int16(nc->memos.memocount, f)); - SAFE(write_int16(nc->memos.memomax, f)); - memos = nc->memos.memos; - for (j = 0; j < nc->memos.memocount; j++, memos++) { - SAFE(write_int32(memos->number, f)); - SAFE(write_int16(memos->flags, f)); - SAFE(write_int32(memos->time, f)); - SAFE(write_buffer(memos->sender, f)); - SAFE(write_string(memos->text, f)); - } - SAFE(write_int16(nc->channelcount, f)); - SAFE(write_int16(nc->channelcount, f)); // BK with anope1.7, hack alert XXX - } /* for (nc) */ - SAFE(write_int8(0, f)); - } /* for (i) */ - - /* Nick aliases */ - for (i = 0; i < 1024; i++) { - for (na = nalists[i]; na; na = na->next) { - SAFE(write_int8(1, f)); - SAFE(write_string(na->nick, f)); - SAFE(write_string(na->last_usermask, f)); - SAFE(write_string(na->last_realname, f)); - SAFE(write_string(na->last_quit, f)); - SAFE(write_int32(na->time_registered, f)); - SAFE(write_int32(na->last_seen, f)); - SAFE(write_int16(na->status, f)); - SAFE(write_string(na->nc->display, f)); - - } /* for (na) */ - SAFE(write_int8(0, f)); - } /* for (i) */ - close_db(f); /* End of section Ic */ - printf("Nick merging done. New database saved as %s.\n", NICK_DB_NEW); - } - } /* End of section I */ - - /* Section II: Chans */ - /* IIa: First database */ - if ((f = open_db_read("ChanServ", CHAN_DB_1, 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; + dbFILE *f; + int i; + NickCore *nc, *ncnext; + HostCore *firsthc = NULL; + + printf("\n"C_LBLUE"DB Merger v0.4 beta for Anope IRC Services by Certus"C_NONE"\n\n"); + + if (argc >= 2) { + if (!mystricmp(argv[1], "--PREFEROLDEST")) { + printf("Preferring oldest database entries on collision.\n"); + preferoldest = 1; + } else if (!mystricmp(argv[1], "--PREFERFIRST")) { + printf("Preferring first database's entries on collision .\n"); + preferfirst = 1; + } else if (!mystricmp(argv[1], "--PREFERSECOND")) { + printf("Preferring second database's entries on collision.\n"); + prefersecond = 1; + } else if (!mystricmp(argv[1], "--PREFERNEWEST")) { + printf("Preferring newest database entries on collision.\n"); + prefernewest = 1; + } + } + + /* Section I: Nicks */ + /* Ia: First database */ + if ((f = open_db_read("NickServ", NICK_DB_1, 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 %s.\n", NICK_DB_1); + exit(0); + } + + nc = (NickCore *)calloc(1, sizeof(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; + access = (char **)calloc(sizeof(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; + memos = (Memo *)calloc(sizeof(Memo) * nc->memos.memocount, 1); + 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 %s.\n", NICK_DB_1); + exit(0); + } + + na = (NickAlias *)calloc(1, sizeof(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); + + *nalast = na; + nalast = &na->next; + na->prev = naprev; + naprev = na; + } /* getc_db() */ + *nalast = NULL; + } /* for() loop */ + close_db(f); /* End of section Ia */ + } else + nonick = 1; + + /* Ib: Second database */ + if (!nonick) { + if ((f = open_db_read("NickServ", NICK_DB_2, 14))) { + + NickAlias *na, *naptr; + NickCore *nc; + int16 tmp16; + int32 tmp32; + int i, j, index, c; + + /* Nick cores */ + for (i = 0; i < 1024; i++) { + + while ((c = getc_db(f)) == 1) { + if (c != 1) { + printf("Invalid format in %s.\n", NICK_DB_2); + exit(0); + } + + nc = (NickCore *)calloc(1, sizeof(NickCore)); + READ(read_string(&nc->display, f)); + READ(read_buffer(nc->pass, f)); + READ(read_string(&nc->email, f)); + + naptr = findnick(nc->display); + if (naptr) + nc->unused = 1; + else + nc->unused = 0; + + nc->aliascount = 0; + + index = HASH(nc->display); + nc->prev = NULL; + nc->next = nclists[index]; + if (nc->next) + nc->next->prev = nc; + nclists[index] = nc; + + 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; + access = (char **)calloc(sizeof(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; + memos = (Memo *)calloc(sizeof(Memo) * nc->memos.memocount, 1); + 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() */ + } /* for() loop */ + + /* Nick aliases */ + for (i = 0; i < 1024; i++) { + char *s = NULL; |
