summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/tools/db-convert.c315
-rw-r--r--src/tools/db-convert.h180
2 files changed, 116 insertions, 379 deletions
diff --git a/src/tools/db-convert.c b/src/tools/db-convert.c
index 7d945fb0b..3523f3e92 100644
--- a/src/tools/db-convert.c
+++ b/src/tools/db-convert.c
@@ -22,7 +22,7 @@ int main(int argc, char *argv[])
std::ofstream fs;
std::string hashm;
- printf("\n"C_LBLUE"Anope 1.8.x -> 1.9.x database converter"C_NONE"\n\n");
+ printf("\n"C_LBLUE"Anope 1.8.x -> 1.9.2+ database converter"C_NONE"\n\n");
hashm = "plain"; // XXX
/*
@@ -667,242 +667,159 @@ int main(int argc, char *argv[])
/* Section III: Bots */
/* IIIa: First database */
if ((f = open_db_read("Botserv", "bot.db", 10))) {
- BotInfo *bi;
- int c;
- int32 tmp32;
- int16 tmp16;
+ std::string input;
+ int c, broken = 0;
+ int32 created;
+ int16 flags, chancount;
+ char *nick, *user, *host, *real;
- printf("Trying to merge bots...\n");
+ std::cout << "Trying to convert bots..." << std::endl;
- while ((c = getc_db(f)) == 1) {
- if (c != 1) {
- printf("Invalid format in %s.\n", "bot.db");
- exit(0);
- }
+ while (input != "y" && input != "n")
+ {
+ std::cout << std::endl << "Are you converting an old 1.9.0 Database? (y/n) ? ";
+ std::cin >> input;
+ }
+ if (input == "y")
+ broken = 1;
- bi = (BotInfo *)calloc(sizeof(BotInfo), 1);
- READ(read_string(&bi->nick, f));
- READ(read_string(&bi->user, f));
- READ(read_string(&bi->host, f));
- READ(read_string(&bi->real, f));
- SAFE(read_int16(&tmp16, f));
- bi->flags = tmp16;
- READ(read_int32(&tmp32, f));
- bi->created = tmp32;
- READ(read_int16(&tmp16, f));
- bi->chancount = tmp16;
- insert_bot(bi);
+ 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));
/* fix for the 1.9.0 broken bot.db */
- if ((stricmp(bi->nick, "ChanServ")==0) && !(bi->flags & BI_CHANSERV))
- {
- bi->flags = 0;
- bi->flags |= BI_CHANSERV;
- }
- if ((stricmp(bi->nick, "BotServ")==0) && !(bi->flags & BI_BOTSERV))
- {
- bi->flags = 0;
- bi->flags |= BI_BOTSERV | BI_PRIVATE;
- }
- if ((stricmp(bi->nick, "HostServ")==0) && !(bi->flags & BI_HOSTSERV))
+ if (broken)
{
- bi->flags = 0;
- bi->flags |= BI_HOSTSERV | BI_PRIVATE;
- }
- if ((stricmp(bi->nick, "OperServ")==0) && !(bi->flags & BI_OPERSERV))
- {
- bi->flags = 0;
- bi->flags |= BI_OPERSERV | BI_PRIVATE;
- }
- if ((stricmp(bi->nick, "MemoServ")==0) && !(bi->flags & BI_MEMOSERV))
- {
- bi->flags = 0;
- bi->flags |= BI_MEMOSERV | BI_PRIVATE;
- }
- if ((stricmp(bi->nick, "NickServ")==0) && !(bi->flags & BI_NICKSERV))
- {
- bi->flags = 0;
- bi->flags |= BI_NICKSERV | BI_PRIVATE;
- }
- if ((stricmp(bi->nick, "Global")==0) && !(bi->flags & BI_GLOBAL))
- {
- bi->flags = 0;
- bi->flags |= BI_GLOBAL | BI_PRIVATE;
- }
- /* end of 1.9.0 broken database fix */
+ flags = 0;
+ if (!stricmp(nick, "ChanServ"))
+ flags |= BI_CHANSERV;
+ if (!stricmp(nick, "BotServ"))
+ flags |= BI_BOTSERV | BI_PRIVATE;
+ if (!stricmp(nick, "HostServ"))
+ flags |= BI_HOSTSERV | BI_PRIVATE;
+ if (!stricmp(nick, "OperServ"))
+ flags |= BI_OPERSERV | BI_PRIVATE;
+ if (!stricmp(nick, "MemoServ"))
+ flags |= BI_MEMOSERV | BI_PRIVATE;
+ if (!stricmp(nick, "NickServ"))
+ flags |= BI_NICKSERV | BI_PRIVATE;
+ if (!stricmp(nick, "Global"))
+ flags |= BI_GLOBAL | BI_PRIVATE;
+ } /* 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 BI 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);
}
- /* IIIc: Saving */
- BotInfo *bi;
- for (i = 0; i < 256; i++)
- {
- for (bi = botlists[i]; bi; bi = bi->next)
- {
- std::cout << "Writing Bot " << bi->nick << "!" << bi->user << "@" << bi->host << std::endl;
- fs << "BI " << bi->nick << " " << bi->user << " " << bi->host << " "
- << bi->created << " " << bi->chancount << " :" << bi->real << std::endl;
- fs << "MD BI flags "
- << (( bi->flags & BI_PRIVATE ) ? "PRIVATE " : "" )
- << (( bi->flags & BI_CHANSERV ) ? "CHANSERV " : "" )
- << (( bi->flags & BI_BOTSERV ) ? "BOTSERV " : "" )
- << (( bi->flags & BI_HOSTSERV ) ? "HOSTSERV " : "" )
- << (( bi->flags & BI_OPERSERV ) ? "OPERSERV " : "" )
- << (( bi->flags & BI_MEMOSERV ) ? "MEMOSERV " : "" )
- << (( bi->flags & BI_NICKSERV ) ? "NICKSERV " : "" )
- << (( bi->flags & BI_GLOBAL ) ? "GLOBAL " : "" ) << std::endl;
- } // for (botflists[i])
- } // for (i)
-
/* Section IV: Hosts */
/* IVa: First database */
- HostCore *hc, *firsthc;
if ((f = open_db_read("HostServ", "hosts.db", 3))) {
int c;
- int32 tmp32;
+ int32 time;
+ char *nick, *vIdent, *vHost, *creator;
- printf("Trying to merge hosts...\n");
+ std::cout << "Converting hosts..." << std::endl;
while ((c = getc_db(f)) == 1) {
- if (c != 1) {
- printf("Invalid format in %s.\n", "hosts.db");
- exit(0);
- }
- hc = (HostCore *)calloc(1, sizeof(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(&tmp32, f));
- hc->time = tmp32;
- hc->next = firsthc;
- if (firsthc)
- firsthc->last = hc;
- hc->last = NULL;
- firsthc = hc;
+ READ(read_string(&nick, f));
+ READ(read_string(&vIdent, f));
+ READ(read_string(&vHost, f));
+ READ(read_string(&creator, f));
+ READ(read_int32(&time, f));
+ std::cout << "Writing vHost for " << nick << " (" << vIdent << "@" << vHost << ")" << std::endl;
+ // because vIdent can sometimes be empty, we put it at the end of the list
+ fs << "HI " << nick << " " << creator << " " << time << " " << vHost << " "
+ << (vIdent ? vIdent : "") << std::endl;
+ free(nick); if (vIdent) free(vIdent); free(vHost); free(creator);
}
close_db(f);
- }
- /* IVb: Saving */
- for (hc = firsthc; hc; hc = hc->next)
- { // because vIdent can sometimes be empty, we put it at the end of the list
- std::cout << "Writing vHost for " << hc->nick << " (" << hc->vIdent << "@" << hc->vHost << ")" << std::endl;
- fs << "HI " << hc->nick << " " << hc->creator << " " << hc->time << " "
- << hc->vHost << " " << hc->vIdent << std::endl;
- } // for (hc)
+ } // host database
/*********************************/
/* OPERSERV Section */
/*********************************/
- int32 maxusercnt = 0;
- int32 maxusertime = 0;
- SList akills, sglines, sqlines, szlines;
- Akill *ak;
- SXLine *sx;
-
if ((f = open_db_read("OperServ", "oper.db", 13)))
{
- int16 tmp16;
- int32 tmp32;
+ 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(&tmp32, f));
- maxusertime = tmp32;
+ SAFE(read_int32(&maxusertime, f));
+ fs << "OS STATS " << maxusercnt << " " << maxusertime << std::endl;
- read_int16(&tmp16, f);
- slist_setcapacity(&akills, tmp16);
- for (i = 0; i < akills.capacity; i++)
+ /* AKILLS */
+ read_int16(&capacity, f);
+ for (i = 0; i < capacity; i++)
{
- ak = new Akill;
- SAFE(read_string(&ak->user, f));
- SAFE(read_string(&ak->host, f));
- SAFE(read_string(&ak->by, f));
- SAFE(read_string(&ak->reason, f));
- SAFE(read_int32(&tmp32, f));
- ak->seton = tmp32;
- SAFE(read_int32(&tmp32, f));
- ak->expires = tmp32;
- slist_add(&akills, ak);
+ 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;
+ free(user); free(host); free(by); free(reason);
}
-
- read_int16(&tmp16, f);
- slist_setcapacity(&sglines, tmp16);
- for (i = 0; i < sglines.capacity; i++)
+ /* SGLINES */
+ read_int16(&capacity, f);
+ for (i = 0; i < capacity; i++)
{
- sx = new SXLine;
- SAFE(read_string(&sx->mask, f));
- SAFE(read_string(&sx->by, f));
- SAFE(read_string(&sx->reason, f));
- SAFE(read_int32(&tmp32, f));
- sx->seton = tmp32;
- SAFE(read_int32(&tmp32, f));
- sx->expires = tmp32;
- slist_add(&sglines, sx);
+ 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 SGLINE " << mask << " " << by << " " << seton << " " << expires << " :" << reason << std::endl;
+ free(mask); free(by); free(reason);
}
-
- read_int16(&tmp16, f);
- slist_setcapacity(&sqlines, tmp16);
- for (i = 0; i < sqlines.capacity; i++)
+ /* SQLINES */
+ read_int16(&capacity, f);
+ for (i = 0; i < capacity; i++)
{
- sx = new SXLine;
- SAFE(read_string(&sx->mask, f));
- SAFE(read_string(&sx->by, f));
- SAFE(read_string(&sx->reason, f));
- SAFE(read_int32(&tmp32, f));
- sx->seton = tmp32;
- SAFE(read_int32(&tmp32, f));
- sx->expires = tmp32;
- slist_add(&sqlines, sx);
+ 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;
+ free(mask); free(by); free(reason);
}
-
- read_int16(&tmp16, f);
- slist_setcapacity(&szlines, tmp16);
- for (i = 0; i < szlines.capacity; i++)
+ /* SZLINES */
+ read_int16(&capacity, f);
+ for (i = 0; i < capacity; i++)
{
- sx = new SXLine;
- SAFE(read_string(&sx->mask, f));
- SAFE(read_string(&sx->by, f));
- SAFE(read_string(&sx->reason, f));
- SAFE(read_int32(&tmp32, f));
- sx->seton = tmp32;
- SAFE(read_int32(&tmp32, f));
- sx->expires = tmp32;
- slist_add(&szlines, sx);
+ 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;
+ free(mask); free(by); free(reason);
}
- close_db(f); // oper.db
- } // if (open_db_read)
- /* done reading oper.db, now lets save the data in the new format */
-
- std::cout << "Writing operserv data (stats, akills, sglines, szlines)" << std::endl;
- fs << "OS STATS " << maxusercnt << " " << maxusertime << std::endl;
+ close_db(f);
+ } // operserv database
- for (i = 0; i < akills.count; i++)
- {
- ak = static_cast<Akill *>(akills.list[i]);
- fs << "OS AKILL " << ak->user << " " << ak->host << " " << ak->by << " "
- << ak->seton << " " << ak->expires << " :" << ak->reason << std::endl;
- }
- for (i = 0; i < sglines.count; i++)
- {
- sx = static_cast<SXLine *>(sglines.list[i]);
- fs << "OS SGLINE " << sx->mask << " " << sx->by << " " << sx->seton << " "
- << sx->expires << " :" << sx->reason << std::endl;
- }
- for (i = 0; i < sqlines.count; i++)
- {
- sx = static_cast<SXLine *>(sqlines.list[i]);
- fs << "OS SQLINE " << sx->mask << " " << sx->by << " " << sx->seton << " "
- << sx->expires << " :" << sx->reason << std::endl;
- }
- for (i = 0; i < szlines.count; i++)
- {
- sx = static_cast<SXLine *>(szlines.list[i]);
- fs << "OS SZLINE " << sx->mask << " " << sx->by << " " << sx->seton << " "
- << sx->expires << " :" << sx->reason << std::endl;
- }
- /* MERGING DONE \o/ HURRAY! */
+ /* CONVERTING DONE \o/ HURRAY! */
fs.close();
printf("\n\nMerging is now done. I give NO guarantee for your DBs.\n");
return 0;
diff --git a/src/tools/db-convert.h b/src/tools/db-convert.h
index 58d61df82..27fd636b5 100644
--- a/src/tools/db-convert.h
+++ b/src/tools/db-convert.h
@@ -67,13 +67,7 @@ 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;
-typedef struct akill_ Akill;
-typedef struct sxline_ SXLine;
-typedef struct slist_ SList;
-typedef struct slistopts_ SListOpts;
struct memo_ {
uint32 number; /* Index number -- not necessarily array position! */
@@ -188,92 +182,17 @@ struct chaninfo_ {
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. */
-};
-
struct badword_ {
uint16 in_use;
char *word;
uint16 type;
};
-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 */
-};
-
-struct akill_ {
- char *user; /* User part of the AKILL */
- char *host; /* Host part of the AKILL */
-
- char *by; /* Who set the akill */
- char *reason; /* Why they got akilled */
-
- time_t seton; /* When it was set */
- time_t expires; /* When it expires */
-};
-
-/*************************************************************************/
-
-/* Structure for OperServ SGLINE and SZLINE commands */
-
-struct sxline_ {
- char *mask;
- char *by;
- char *reason;
- time_t seton;
- time_t expires;
-};
-
-struct slist_ {
- void **list;
-
- int16 count; /* Total entries of the list */
- int16 capacity; /* Capacity of the list */
- int16 limit; /* Maximum possible entries on the list */
-
- SListOpts *opts;
-};
-
-
-struct slistopts_ {
- int32 flags; /* Flags for the list. See below. */
-
- int (*compareitem) (SList *slist, void *item1, void *item2); /* Called to compare two items */
- int (*isequal) (SList *slist, void *item1, void *item2); /* Called by slist_indexof. item1 can be an arbitrary pointer. */
- void (*freeitem) (SList *slist, void *item); /* Called when an item is removed */
-};
-
-
-#define SLIST_DEFAULT_LIMIT 32767
-
-#define SLISTF_NODUP 0x00000001 /* No duplicates in the list. */
-#define SLISTF_SORT 0x00000002 /* Automatically sort the list. Used with compareitem member. */
-
-/* Note that number is the index in the array + 1 */
-typedef int (*slist_enumcb_t) (SList *slist, int number, void *item, va_list args);
-/* Callback to know whether we can delete the entry. */
-typedef int (*slist_delcheckcb_t) (SList *slist, void *item, va_list args);
-
-
dbFILE *open_db_write(const char *service, const char *filename, int version);
dbFILE *open_db_read(const char *service, const char *filename, int version);
NickCore *findcore(const char *nick, int version);
NickAlias *findnick(const char *nick);
-BotInfo *findbot(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);
@@ -291,13 +210,11 @@ 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);
ChannelInfo *chanlists[256];
NickAlias *nalists[1024];
NickCore *nclists[1024];
-BotInfo *botlists[256];
int b64_encode(char *src, size_t srclength, char *target, size_t targsize);
@@ -827,33 +744,6 @@ int delcore(NickCore *nc)
return 1;
}
-void insert_bot(BotInfo * bi)
-{
- BotInfo *ptr, *prev;
-
- for (prev = NULL, ptr = botlists[tolower(*bi->nick)];
- ptr != NULL && mystricmp(ptr->nick, bi->nick) < 0;
- prev = ptr, ptr = ptr->next);
- bi->prev = prev;
- bi->next = ptr;
- if (!prev)
- botlists[tolower(*bi->nick)] = bi;
- else
- prev->next = bi;
- if (ptr)
- ptr->prev = bi;
-}
-
-BotInfo *findbot(char *nick)
-{
- BotInfo *bi;
-
- for (bi = botlists[tolower(*nick)]; bi; bi = bi->next)
- if (!mystricmp(nick, bi->nick))
- return bi;
-
- return NULL;
-}
ChannelInfo *cs_findchan(const char *chan)
{
@@ -1236,73 +1126,3 @@ int stricmp(const char *s1, const char *s2)
return -1;
return 1;
}
-
-int slist_setcapacity(SList * slist, int16 capacity)
-{
- if (slist->capacity == capacity)
- return 1;
- slist->capacity = capacity;
- if (slist->capacity)
- slist->list = static_cast<void **>(realloc(slist->list, sizeof(void *) * slist->capacity));
- else {
- free(slist->list);
- slist->list = NULL;
- }
- if (slist->capacity < slist->count)
- slist->count = slist->capacity;
- return 1;
-}
-
-int slist_indexof(SList * slist, void *item)
-{
- int16 i;
- void *entry;
-
- if (slist->count == 0)
- return -1;
-
- for (i = 0, entry = slist->list[0]; i < slist->count;
- i++, entry = slist->list[i]) {
- if ((slist->opts
- && slist->opts->isequal) ? (slist->opts->isequal(slist, item,
- entry))
- : (item == entry))
- return i;
- }
-
- return -1;
-}
-
-
-int slist_add(SList * slist, void *item)
-{
- if (slist->limit != 0 && slist->count >= slist->limit)
- return -2;
- if (slist->opts && (slist->opts->flags & SLISTF_NODUP)
- && slist_indexof(slist, item) != -1)
- return -3;
- if (slist->capacity == slist->count)
- slist_setcapacity(slist, slist->capacity + 1);
-
- if (slist->opts && (slist->opts->flags & SLISTF_SORT)
- && slist->opts->compareitem) {
- int i;
-
- for (i = 0; i < slist->count; i++) {
- if (slist->opts->compareitem(slist, item, slist->list[i]) <= 0) {
- memmove(&slist->list[i + 1], &slist->list[i],
- sizeof(void *) * (slist->count - i));
- slist->list[i] = item;
- break;
- }
- }
-
- if (i == slist->count)
- slist->list[slist->count] = item;
- } else {
- slist->list[slist->count] = item;
- }
-
- return slist->count++;
-}
-