summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorNaram Qashat <cyberbotx@cyberbotx.com>2010-06-27 23:15:05 -0400
committerNaram Qashat <cyberbotx@cyberbotx.com>2010-06-27 23:15:05 -0400
commit28e12bc24a9c85f4f0d1e37567618ec39cb501f6 (patch)
treecc70ebeef95a9d95174afe3ef038b0d673346f58 /src/tools
parent051ebe3eea0f8529b64c0e443c61103ba2f7dee8 (diff)
The next of a few "CBX OCDing over code style" commits, maybe the last.
NOTES: I have been unable to compile the db_mysql_* functions on my system here, so those are untested. db-convert seems to be badly programmed and needs more work in my opinion.
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/CMakeLists.txt4
-rw-r--r--src/tools/anopesmtp.cpp (renamed from src/tools/anopesmtp.c)439
-rw-r--r--src/tools/db-convert.cpp (renamed from src/tools/db-convert.c)443
-rw-r--r--src/tools/db-convert.h871
-rw-r--r--src/tools/smtp.h95
5 files changed, 850 insertions, 1002 deletions
diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt
index 47801567b..b22a796a4 100644
--- a/src/tools/CMakeLists.txt
+++ b/src/tools/CMakeLists.txt
@@ -13,6 +13,10 @@ foreach(SRC ${TOOLS_SRCS})
string(REGEX REPLACE "\\.(c|cpp)$" "" EXE ${SRC})
# Calculate the header file dependencies for the given source file
calculate_depends(${SRC})
+ # For anoptsmtp, we also want hashcomp.cpp included, so we force it into the sources
+ if(SRC STREQUAL anopesmtp.cpp)
+ set(SRC ${SRC} ${Anope_SOURCE_DIR}/src/hashcomp.cpp)
+ endif(SRC STREQUAL anopesmtp.cpp)
# Generate the executable and set it's linker flags, also set it to depend on the main Anope executable to be built beforehand
add_executable(${EXE} ${SRC})
set_target_properties(${EXE} PROPERTIES LINKER_LANGUAGE CXX LINK_FLAGS "${LDFLAGS}")
diff --git a/src/tools/anopesmtp.c b/src/tools/anopesmtp.cpp
index 5b4fa2202..aedbee725 100644
--- a/src/tools/anopesmtp.c
+++ b/src/tools/anopesmtp.cpp
@@ -10,7 +10,6 @@
*
* Written by Dominick Meglio <codemastr@unrealircd.com>
* *nix port by Trystan Scott Lee <trystan@nomadirc.net>
- *
*/
#include "smtp.h"
@@ -20,37 +19,18 @@ static int curday = 0;
/*************************************************************************/
-/*#ifdef _WIN32
-int strcasecmp(const char *s1, const char *s2)
+static int get_logname(std::string &name, struct tm *tm = NULL)
{
- register int c;
-
- while ((c = tolower(*s1)) == tolower(*s2)) {
- if (c == 0)
- return 0;
- s1++;
- s2++;
- }
- if (c < tolower(*s2))
- return -1;
- return 1;
-}
-#endif*/
-
-static int get_logname(char *name, int count, struct tm *tm)
-{
-
char timestamp[32];
- if (!tm) {
- time_t t;
-
- time(&t);
+ if (!tm)
+ {
+ time_t t = time(NULL);
tm = localtime(&t);
}
- strftime(timestamp, count, "%Y%m%d", tm);
- snprintf(name, count, "logs/%s.%s", "anopesmtp", timestamp);
+ strftime(timestamp, sizeof(timestamp), "%Y%m%d", tm);
+ name = std::string("logs/anopesmtp.") + timestamp;
curday = tm->tm_yday;
return 1;
@@ -72,18 +52,14 @@ void close_log()
static void remove_log()
{
- time_t t;
- struct tm tm;
-
- char name[PATH_MAX];
+ time_t t = time(NULL);
+ t -= 2592000; // 30 days ago
+ struct tm *tm = localtime(&t);
- time(&t);
- t -= (60 * 60 * 24 * 30);
- tm = *localtime(&t);
-
- if (!get_logname(name, sizeof(name), &tm))
+ std::string name;
+ if (!get_logname(name, tm))
return;
- unlink(name);
+ unlink(name.c_str());
}
/*************************************************************************/
@@ -93,31 +69,25 @@ static void remove_log()
int open_log()
{
- char name[PATH_MAX];
-
if (logfile)
return 0;
- if (!get_logname(name, sizeof(name), NULL))
+ std::string name;
+ if (!get_logname(name))
return 0;
- logfile = fopen(name, "a");
-
- if (logfile)
- setbuf(logfile, NULL);
- return logfile != NULL ? 0 : -1;
+ logfile = fopen(name.c_str(), "w");
+ return logfile ? 0 : -1;
}
/*************************************************************************/
static void checkday()
{
- time_t t;
- struct tm tm;
-
- time(&t);
- tm = *localtime(&t);
+ time_t t = time(NULL);
+ struct tm *tm = localtime(&t);
- if (curday != tm.tm_yday) {
+ if (curday != tm->tm_yday)
+ {
close_log();
remove_log();
open_log();
@@ -132,27 +102,26 @@ static void checkday()
void alog(const char *fmt, ...)
{
- va_list args;
- time_t t;
- struct tm tm;
- char buf[256];
int errno_save = errno;
- if (!smtp_debug) {
+ if (!smtp_debug)
return;
- }
checkday();
- if (!fmt) {
+ if (!fmt)
return;
- }
+ va_list args;
va_start(args, fmt);
- time(&t);
- tm = *localtime(&t);
- strftime(buf, sizeof(buf) - 1, "[%b %d %H:%M:%S %Y] ", &tm);
- if (logfile && args) {
+
+ time_t t = time(NULL);
+ struct tm *tm = localtime(&t);
+
+ char buf[256];
+ strftime(buf, sizeof(buf) - 1, "[%b %d %H:%M:%S %Y] ", tm);
+ if (logfile)
+ {
fputs(buf, logfile);
vfprintf(logfile, fmt, args);
fputc('\n', logfile);
@@ -164,142 +133,91 @@ void alog(const char *fmt, ...)
/*************************************************************************/
/* Remove a trailing \r\n */
-char *strip(char *buf)
-{
- char *c;
- if ((c = strchr(buf, '\n')))
- *c = 0;
- if ((c = strchr(buf, '\r')))
- *c = 0;
- return buf;
-}
-
-/*************************************************************************/
-
-/* Convert a trailing \n to \r\n
- * The caller must free the allocated memory
- */
-char *lftocrlf(char *buf)
+ci::string strip(const ci::string &buf)
{
- char *result = (char *)malloc(strlen(buf) + 2);
- strip(buf);
- strcpy(result, buf);
- strcat(result, "\r\n");
- return result;
-}
-
-/*************************************************************************/
-
-/* Add a header to the list */
-void smtp_add_header(char *header)
-{
- struct smtp_header *head = (struct smtp_header *)malloc(sizeof(struct smtp_header));
-
- head->header = lftocrlf(header);
- head->next = NULL;
-
- if (!mail.smtp_headers) {
- mail.smtp_headers = head;
- }
- if (mail.smtp_headers_tail) {
- mail.smtp_headers_tail->next = head;
- }
- mail.smtp_headers_tail = head;
+ ci::string newbuf = buf;
+ char c = newbuf[newbuf.size() - 1];
+ while (c == '\n' || c == '\r')
+ {
+ newbuf.erase(newbuf.end() - 1);
+ c = newbuf[newbuf.size() - 1];
+ }
+ return newbuf;
}
/*************************************************************************/
/* Is the buffer a header? */
-int smtp_is_header(char *buf)
+bool smtp_is_header(const ci::string &buf)
{
- char *tmp = strchr(buf, ' ');
+ size_t tmp = buf.find(' ');
- if (!tmp)
- return 0;
+ if (tmp == ci::string::npos)
+ return false;
- if (*(tmp - 1) == ':')
- return 1;
- return 0;
+ if (buf[tmp + 1] == ':')
+ return true;
+ return false;
}
/*************************************************************************/
/* Parse a header into a name and value */
-void smtp_parse_header(char *buf, char **header, char **value)
+void smtp_parse_header(const ci::string &buf, ci::string &header, ci::string &value)
{
- strip(buf);
+ ci::string newbuf = strip(buf);
- *header = strtok(buf, " ");
- *value = strtok(NULL, "");
- if (*header)
- (*header)[strlen(*header) - 1] = 0;
+ size_t space = newbuf.find(' ');
+ if (space != ci::string::npos)
+ {
+ header = newbuf.substr(0, space);
+ value = newbuf.substr(space + 1);
+ }
+ else
+ {
+ header = newbuf;
+ value = "";
+ }
}
/*************************************************************************/
/* Have we reached the end of input? */
-int smtp_is_end(char *buf)
+bool smtp_is_end(const ci::string &buf)
{
- if (*buf == '.')
- if (*(buf + 1) == '\r' || *(buf + 1) == '\n')
- return 1;
+ if (buf[0] == '.')
+ if (buf[1] == '\r' || buf[1] == '\n')
+ return true;
- return 0;
-}
-
-/*************************************************************************/
-
-/* Set who the email is from */
-void smtp_set_from(char *from)
-{
- mail.from = strdup(from);
+ return false;
}
/*************************************************************************/
/* Set who the email is to */
-void smtp_set_to(char *to)
+void smtp_set_to(const ci::string &to)
{
- char *c;
-
- if ((c = strrchr(to, '<')) && *(c + 1)) {
- to = c + 1;
- to[strlen(to) - 1] = 0;
+ mail.to = to;
+ size_t c = mail.to.rfind('<');
+ if (c != ci::string::npos && c + 1 < mail.to.size())
+ {
+ mail.to = mail.to.substr(c + 1);
+ mail.to.erase(mail.to.end() - 1);
}
- mail.to = strdup(to);
-}
-
-/*************************************************************************/
-
-/* Add a line of body text */
-void smtp_add_body_line(char *line)
-{
- struct smtp_body_line *body;
-
- body = (struct smtp_body_line *)malloc(sizeof(struct smtp_body_line));
-
- body->line = lftocrlf(line);
- body->next = NULL;
-
- if (!mail.smtp_body)
- mail.smtp_body = body;
- if (mail.smtp_body_tail)
- mail.smtp_body_tail->next = body;
- mail.smtp_body_tail = body;
-
}
/*************************************************************************/
/* Establish a connection to the SMTP server */
-int smtp_connect(char *host, unsigned short port)
+int smtp_connect(const char *host, unsigned short port)
{
struct sockaddr_in addr;
if ((mail.sock = socket(AF_INET, SOCK_STREAM, 0)) == SOCKET_ERROR)
return 0;
- if ((addr.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE) {
+ if ((addr.sin_addr.s_addr = inet_addr(host)) == INADDR_NONE)
+ {
struct hostent *hent;
if (!(hent = gethostbyname(host)))
return 0;
@@ -307,7 +225,8 @@ int smtp_connect(char *host, unsigned short port)
}
addr.sin_family = AF_INET;
addr.sin_port = htons(port ? port : 25);
- if (connect(mail.sock, (struct sockaddr *) &addr, sizeof(struct sockaddr_in)) == SOCKET_ERROR) {
+ if (connect(mail.sock, reinterpret_cast<struct sockaddr *>(&addr), sizeof(struct sockaddr_in)) == SOCKET_ERROR)
+ {
ano_sockclose(mail.sock);
return 0;
}
@@ -349,14 +268,14 @@ int smtp_read(char *buf, int len)
/*************************************************************************/
/* Retrieve a response code */
-int smtp_get_code(char *text)
+int smtp_get_code(const std::string &text)
{
- char *tmp = strtok(text, " ");
+ size_t tmp = text.find(' ');
- if (!tmp)
+ if (tmp == ci::string::npos)
return 0;
- return atol(tmp);
+ return atol(text.c_str());
}
/*************************************************************************/
@@ -365,48 +284,50 @@ int smtp_get_code(char *text)
int smtp_send_email()
{
char buf[1024];
- struct smtp_header *head;
- struct smtp_body_line *body;
- int code;
- int skip_done = 0;
-
- if (!smtp_read(buf, 1024)) {
+ if (!smtp_read(buf, 1024))
+ {
alog("SMTP: error reading buffer");
return 0;
}
- code = smtp_get_code(buf);
- if (code != 220) {
+ int code = smtp_get_code(buf);
+ if (code != 220)
+ {
alog("SMTP: error expected code 220 got %d",code);
return 0;
}
- if (!smtp_send("HELO anope\r\n")) {
+ if (!smtp_send("HELO anope\r\n"))
+ {
alog("SMTP: error writting to socket");
return 0;
- }
+ }
- if (!smtp_read(buf, 1024)) {
- alog("SMTP: error reading buffer");
+ if (!smtp_read(buf, 1024))
+ {
+ alog("SMTP: error reading buffer");
return 0;
}
code = smtp_get_code(buf);
- if (code != 250) {
+ if (code != 250)
+ {
alog("SMTP: error expected code 250 got %d",code);
return 0;
}
strcpy(buf, "MAIL FROM: <");
- strcat(buf, mail.from);
+ strcat(buf, mail.from.c_str());
strcat(buf, ">\r\n");
- if (!smtp_send(buf)) {
+ if (!smtp_send(buf))
+ {
alog("SMTP: error writting to socket");
return 0;
}
- if (!smtp_read(buf, 1024)) {
+ if (!smtp_read(buf, 1024))
+ {
alog("SMTP: error reading buffer");
return 0;
}
@@ -416,65 +337,75 @@ int smtp_send_email()
return 0;
strcpy(buf, "RCPT TO: <");
- strcat(buf, mail.to);
+ strcat(buf, mail.to.c_str());
strcat(buf, ">\r\n");
- if (!smtp_send(buf)) {
+ if (!smtp_send(buf))
+ {
alog("SMTP: error writting to socket");
return 0;
}
- if (!smtp_read(buf, 1024)) {
+ if (!smtp_read(buf, 1024))
+ {
alog("SMTP: error reading buffer");
return 0;
}
code = smtp_get_code(buf);
- if (smtp_get_code(buf) != 250) {
+ if (smtp_get_code(buf) != 250)
+ {
alog("SMTP: error expected code 250 got %d",code);
return 0;
}
- if (!smtp_send("DATA\r\n")) {
+ if (!smtp_send("DATA\r\n"))
+ {
alog("SMTP: error writting to socket");
return 0;
}
- if (!smtp_read(buf, 1024)) {
+ if (!smtp_read(buf, 1024))
+ {
alog("SMTP: error reading buffer");
return 0;
}
code = smtp_get_code(buf);
- if (code != 354) {
+ if (code != 354)
+ {
alog("SMTP: error expected code 354 got %d",code);
return 0;
}
- for (head = mail.smtp_headers; head; head = head->next) {
- if (!smtp_send(head->header)) {
+ for (std::vector<ci::string>::const_iterator it = mail.smtp_headers.begin(), it_end = mail.smtp_headers.end(); it != it_end; ++it)
+ if (!smtp_send(it->c_str()))
+ {
alog("SMTP: error writting to socket");
return 0;
- }
- }
+ }
- if (!smtp_send("\r\n")) {
+ if (!smtp_send("\r\n"))
+ {
alog("SMTP: error writting to socket");
return 0;
}
- for (body = mail.smtp_body; body; body = body->next) {
- if (skip_done) {
- if (!smtp_send(body->line)) {
+ bool skip_done = false;
+ for (std::vector<ci::string>::const_iterator it = mail.smtp_body.begin(), it_end = mail.smtp_body.end(); it != it_end; ++it)
+ if (skip_done)
+ {
+ if (!smtp_send(it->c_str()))
+ {
alog("SMTP: error writting to socket");
return 0;
}
- } else {
- skip_done = 1;
}
- }
+ else
+ skip_done = true;
- if (!smtp_send("\r\n.\r\n")) {
+ if (!smtp_send("\r\n.\r\n"))
+ {
alog("SMTP: error writting to socket");
return 0;
}
@@ -494,111 +425,97 @@ void smtp_disconnect()
void mail_cleanup()
{
- struct smtp_header *headers, *nexth;
- struct smtp_body_line *body, *nextb;
-
- if (mail.from)
- free(mail.from);
- if (mail.to)
- free(mail.to);
-
- headers = mail.smtp_headers;
- while (headers) {
- nexth = headers->next;
- free(headers->header);
- free(headers);
- headers = nexth;
- }
-
- body = mail.smtp_body;
- while (body) {
- nextb = body->next;
- free(body->line);
- free(body);
- body = nextb;
- }
+ mail.from.clear();
+ mail.to.clear();
+
+ mail.smtp_headers.clear();
+
+ mail.smtp_body.clear();
}
/*************************************************************************/
int main(int argc, char *argv[])
{
- char buf[8192];
-/* These are somehow unused - why are they here? -GD
-
- struct smtp_body_line *b;
- struct smtp_header *h;
-*/
- int headers_done = 0;
-/* Win32 stuff */
+ /* Win32 stuff */
#ifdef _WIN32
WSADATA wsa;
#endif
- char *server, *aport;
- short port;
if (argc == 1)
return 0;
- server = strtok(argv[1], ":");
- if ((aport = strtok(NULL, ""))) {
+ char *server = strtok(argv[1], ":"), *aport;
+ short port;
+ if ((aport = strtok(NULL, "")))
port = atoi(aport);
- } else {
+ else
port = 25;
- }
- if (!server) {
+ if (!server)
+ {
alog("No Server");
- /* Bad, bad, bad. This was a eturn from main with no value! -GD */
+ /* Bad, bad, bad. This was a return from main with no value! -GD */
return 0;
- } else {
- alog("SMTP: server %s port %d",server,port);
}
+ else
+ alog("SMTP: server %s port %d",server,port);
memset(&mail, 0, sizeof(mail));
-/* The WSAStartup function initiates use of WS2_32.DLL by a process. */
-/* guessing we can skip it under *nix */
+ /* The WSAStartup function initiates use of WS2_32.DLL by a process. */
+ /* guessing we can skip it under *nix */
#ifdef _WIN32
- if (WSAStartup(MAKEWORD(1, 1), &wsa) != 0)
+ if (WSAStartup(MAKEWORD(1, 1), &wsa))
return 0;
#endif
+ char buf[8192];
+ bool headers_done = false;
/* Read the message and parse it */
- while (fgets(buf, 8192, stdin)) {
- if (smtp_is_header(buf) && !headers_done) {
- char *header, *value;
- smtp_add_header(buf);
- smtp_parse_header(buf, &header, &value);
- if (!strcasecmp(header, "from")) {
- alog("SMTP: from: %s",value);
- smtp_set_from(value);
- } else if (!strcasecmp(header, "to")) {
- alog("SMTP: to: %s",value);
+ while (fgets(buf, 8192, stdin))
+ {
+ if (smtp_is_header(buf) && !headers_done)
+ {
+ mail.smtp_headers.push_back(strip(buf) + "\r\n");
+ ci::string header, value;
+ smtp_parse_header(buf, header, value);
+ if (header == "from")
+ {
+ alog("SMTP: from: %s", value.c_str());
+ mail.from = value;
+ }
+ else if (header == "to")
+ {
+ alog("SMTP: to: %s", value.c_str());
smtp_set_to(value);
- } else if (smtp_is_end(buf)) {
+ }
+ else if (smtp_is_end(buf))
break;
- } else {
- headers_done = 1;
- smtp_add_body_line(buf);
+ else
+ {
+ headers_done = true;
+ mail.smtp_body.push_back(strip(buf) + "\r\n");
}
- } else {
- smtp_add_body_line(buf);
}
+ else
+ mail.smtp_body.push_back(strip(buf) + "\r\n");
}
- if (!smtp_connect(server, port)) {
- alog("SMTP: failed to connect to %s:%d",server, port);
+ if (!smtp_connect(server, port))
+ {
+ alog("SMTP: failed to connect to %s:%d", server, port);
mail_cleanup();
return 0;
}
- if (!smtp_send_email()) {
+ if (!smtp_send_email())
+ {
alog("SMTP: error during sending of mail");
mail_cleanup();
return 0;
}
smtp_disconnect();
mail_cleanup();
-
+
return 1;
}
diff --git a/src/tools/db-convert.c b/src/tools/db-convert.cpp
index 34bb01d8c..9ee6ee016 100644
--- a/src/tools/db-convert.c
+++ b/src/tools/db-convert.cpp
@@ -44,7 +44,7 @@ static std::string GetLevelName(int level)
return "NOJOIN";
case 11:
return "CHANGE";
- case 12:
+ case 12:
return "MEMO";
case 13:
return "ASSIGN";
@@ -60,7 +60,7 @@ static std::string GetLevelName(int level)
return "GREET";
case 19:
return "VOICEME";
- case 20:
+ case 20:
return "VOICE";
case 21:
return "GETKEY";
@@ -76,9 +76,9 @@ static std::string GetLevelName(int level)
return "HALFOP";
case 27:
return "PROTECTME";
- case 28:
+ case 28:
return "PROTECT";
- case 29:
+ case 29:
return "KICKME";
case 30:
return "KICK";
@@ -100,57 +100,57 @@ static std::string GetLevelName(int level)
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 (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 (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 (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
+ 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
+ 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
- } // if (inspircd)
+ 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[])
@@ -168,11 +168,8 @@ int main(int argc, char *argv[])
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")
+
+ 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;
@@ -184,6 +181,7 @@ int main(int argc, char *argv[])
std::cout << "You selected " << hashm << std::endl;
+ fs.clear();
fs.open("anope.db");
if (!fs.is_open())
{
@@ -198,7 +196,6 @@ int main(int argc, char *argv[])
/* Ia: First database */
if ((f = open_db_read("NickServ", "nick.db", 14)))
{
-
NickAlias *na, **nalast, *naprev;
NickCore *nc, **nclast, *ncprev;
int16 tmp16;
@@ -208,17 +205,20 @@ int main(int argc, char *argv[])
printf("Trying to merge nicks...\n");
/* Nick cores */
- for (i = 0; i < 1024; i++) {
+ for (i = 0; i < 1024; ++i)
+ {
nclast = &nclists[i];
ncprev = NULL;
- while ((c = getc_db(f)) == 1) {
- if (c != 1) {
+ while ((c = getc_db(f)) == 1)
+ {
+ if (c != 1)
+ {
printf("Invalid format in nickserv db.\n");
exit(0);
}
- nc = (NickCore *)calloc(1, sizeof(NickCore));
+ nc = new NickCore;
nc->aliascount = 0;
nc->unused = 0;
@@ -236,20 +236,21 @@ int main(int argc, char *argv[])
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);
+ if (nc->accesscount)
+ {
+ char **access = new char *[nc->accesscount + 1];
nc->access = access;
- for (j = 0; j < nc->accesscount; j++, 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);
+ if (nc->memos.memocount)
+ {
+ Memo *memos = new Memo[nc->memos.memocount];
nc->memos.memos = memos;
- for (j = 0; j < nc->memos.memocount; j++, 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));
@@ -265,19 +266,22 @@ int main(int argc, char *argv[])
} /* for() loop */
/* Nick aliases */
- for (i = 0; i < 1024; i++) {
+ for (i = 0; i < 1024; ++i)
+ {
char *s = NULL;
nalast = &nalists[i];
naprev = NULL;
- while ((c = getc_db(f)) == 1) {
- if (c != 1) {
+ while ((c = getc_db(f)) == 1)
+ {
+ if (c != 1)
+ {
printf("Invalid format in nick db.\n");
exit(0);
}
- na = (NickAlias *)calloc(1, sizeof(NickAlias));
+ na = new NickAlias;
READ(read_string(&na->nick, f));
READ(read_string(&na->last_usermask, f));
@@ -291,8 +295,9 @@ int main(int argc, char *argv[])
READ(read_uint16(&na->status, f));
READ(read_string(&s, f));
na->nc = findcore(s, 0);
- na->nc->aliascount++;
- free(s);
+ ++na->nc->aliascount;
+ //free(s);
+ delete [] s;
*nalast = na;
nalast = &na->next;
@@ -306,11 +311,14 @@ int main(int argc, char *argv[])
/* CLEAN THE CORES */
int i;
- for (i = 0; i < 1024; i++) {
+ for (i = 0; i < 1024; ++i)
+ {
NickCore *ncnext;
- for (NickCore *nc = nclists[i]; nc; nc = ncnext) {
+ for (NickCore *nc = nclists[i]; nc; nc = ncnext)
+ {
ncnext = nc->next;
- if (nc->aliascount < 1) {
+ if (nc->aliascount < 1)
+ {
printf("Deleting core %s (%s).\n", nc->display, nc->email);
delcore(nc);
}
@@ -325,7 +333,7 @@ int main(int argc, char *argv[])
while ((c = getc_db(f)) == 1)
{
- hc = (HostCore *)calloc(1, sizeof(HostCore));
+ hc = new HostCore;
READ(read_string(&hc->nick, f));
READ(read_string(&hc->vIdent, f));
READ(read_string(&hc->vHost, f));
@@ -340,7 +348,7 @@ int main(int argc, char *argv[])
}
/* Nick cores */
- for (i = 0; i < 1024; i++)
+ for (i = 0; i < 1024; ++i)
{
NickAlias *na;
NickCore *nc;
@@ -371,10 +379,10 @@ int main(int argc, char *argv[])
len = 20;
else if (hashm == "oldmd5")
len = 16;
- else
+ else
len = 32;
-
- b64_encode(nc->pass, len, (char *)cpass, 5000);
+
+ b64_encode(nc->pass, len, cpass, 5000);
fs << "NC " << nc->display << " " << hashm << ":" << cpass;
fs << " " << GetLanguageID(nc->language) << " " << nc->memos.memomax << " " << nc->channelcount << std::endl;
@@ -390,34 +398,32 @@ int main(int argc, char *argv[])
fs << "MD URL :" << nc->url << std::endl;
if (nc->accesscount)
- {
- for (j = 0, access = nc->access; j < nc->accesscount && *access; j++, access++)
+ 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;
+ << (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++)
+ for (j = 0; j < nc->memos.memocount; ++j, ++memos)
{
if (!memos->text)
break;
@@ -433,7 +439,7 @@ int main(int argc, char *argv[])
}
/* we could do this in a seperate loop, I'm doing it here for tidiness. */
- for (int tmp = 0; tmp < 1024; tmp++)
+ for (int tmp = 0; tmp < 1024; ++tmp)
{
for (na = nalists[tmp]; na; na = na->next)
{
@@ -455,27 +461,21 @@ int main(int argc, char *argv[])
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;
- }
+ 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)
- {
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))) {
+ if ((f = open_db_read("Botserv", "bot.db", 10)))
+ {
std::string input;
int c, broken = 0;
int32 created;
@@ -523,7 +523,8 @@ int main(int argc, char *argv[])
fs << "MD FLAGS GLOBAL" << std::endl;
}
- while ((c = getc_db(f)) == 1) {
+ while ((c = getc_db(f)) == 1)
+ {
READ(read_string(&nick, f));
READ(read_string(&user, f));
READ(read_string(&host, f));
@@ -532,39 +533,39 @@ int main(int argc, char *argv[])
READ(read_int32(&created, f));
READ(read_int16(&chancount, f));
- if (created == 0)
+ 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 (!stricmp(nick, "ChanServ"))
+ if (!mystricmp(nick, "ChanServ"))
flags |= BI_CHANSERV;
- if (!stricmp(nick, "BotServ"))
+ if (!mystricmp(nick, "BotServ"))
flags |= BI_BOTSERV;
- if (!stricmp(nick, "HostServ"))
+ if (!mystricmp(nick, "HostServ"))
flags |= BI_HOSTSERV;
- if (!stricmp(nick, "OperServ"))
+ if (!mystricmp(nick, "OperServ"))
flags |= BI_OPERSERV;
- if (!stricmp(nick, "MemoServ"))
+ if (!mystricmp(nick, "MemoServ"))
flags |= BI_MEMOSERV;
- if (!stricmp(nick, "NickServ"))
+ if (!mystricmp(nick, "NickServ"))
flags |= BI_NICKSERV;
- if (!stricmp(nick, "Global"))
+ 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;
+ << (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);
}
@@ -578,7 +579,7 @@ int main(int argc, char *argv[])
printf("Trying to merge channels...\n");
- for (i = 0; i < 256; i++)
+ for (i = 0; i < 256; ++i)
{
int16 tmp16;
int32 tmp32;
@@ -599,7 +600,7 @@ int main(int argc, char *argv[])
exit(0);
}
- ci = (ChannelInfo *)calloc(sizeof(ChannelInfo), 1);
+ ci = new ChannelInfo;
*last = ci;
last = &ci->next;
ci->prev = prev;
@@ -631,8 +632,8 @@ int main(int argc, char *argv[])
ci->bantype = tmp16;
READ(read_int16(&tmp16, f));
n_levels = tmp16;
- ci->levels = (int16 *)calloc(36 * sizeof(*ci->levels), 1);
- for (j = 0; j < n_levels; j++)
+ ci->levels = new int16[36];
+ for (j = 0; j < n_levels; ++j)
{
if (j < 36)
READ(read_int16(&ci->levels[j], f));
@@ -642,8 +643,8 @@ int main(int argc, char *argv[])
READ(read_uint16(&ci->accesscount, f));
if (ci->accesscount)
{
- ci->access = (ChanAccess *)calloc(ci->accesscount, sizeof(ChanAccess));
- for (j = 0; j < ci->accesscount; j++)
+ 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)
@@ -653,7 +654,7 @@ int main(int argc, char *argv[])
if (s)
{
ci->access[j].nc = findcore(s, 0);
- free(s);
+ delete [] s;
}
if (ci->access[j].nc == NULL)
ci->access[j].in_use = 0;
@@ -663,14 +664,12 @@ int main(int argc, char *argv[])
}
}
else
- {
ci->access = NULL;
- }
READ(read_uint16(&ci->akickcount, f));
if (ci->akickcount)
{
- ci->akick = (AutoKick *)calloc(ci->akickcount, sizeof(AutoKick));
- for (j = 0; j < ci->akickcount; j++)
+ 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)
@@ -681,26 +680,20 @@ int main(int argc, char *argv[])
ci->akick[j].u.nc = findcore(s, 0);
if (!ci->akick[j].u.nc)
ci->akick[j].flags &= ~0x0001;
- free(s);
+ 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)
- free(s);
+ delete [] s;
SAFE(read_string(&s, f));
if (ci->akick[j].flags & 0x0001)
- {
ci->akick[j].creator = s;
- }
else if (s)
- {
- free(s);
- }
+ delete [] s;
SAFE(read_int32(&tmp32, f));
if (ci->akick[j].flags & 0x0001)
ci->akick[j].addtime = tmp32;
@@ -708,9 +701,7 @@ int main(int argc, char *argv[])
}
}
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));
@@ -721,10 +712,9 @@ int main(int argc, char *argv[])
READ(read_int16(&ci->memos.memomax, f));
if (ci->memos.memocount)
{
- Memo *memos;
- memos = (Memo *)calloc(sizeof(Memo) * ci->memos.memocount, 1);
+ Memo *memos = new Memo[ci->memos.memocount];
ci->memos.memos = memos;
- for (j = 0; j < ci->memos.memocount; j++, memos++)
+ for (j = 0; j < ci->memos.memocount; ++j, ++memos)
{
READ(read_uint32(&memos->number, f));
READ(read_uint16(&memos->flags, f));
@@ -742,15 +732,15 @@ int main(int argc, char *argv[])
ci->botflags = tmp32;
READ(read_int16(&tmp16, f));
n_ttb = tmp16;
- ci->ttb = (int16 *)calloc(2 * 8, 1);
- for (j = 0; j < n_ttb; j++)
+ 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++)
+ for (j = n_ttb; j < 8; ++j)
ci->ttb[j] = 0;
READ(read_int16(&tmp16, f));
ci->capsmin = tmp16;
@@ -766,8 +756,8 @@ int main(int argc, char *argv[])
READ(read_uint16(&ci->bwcount, f));
if (ci->bwcount)
{
- ci->badwords = (BadWord *)calloc(ci->bwcount, sizeof(BadWord));
- for (j = 0; j < ci->bwcount; j++)
+ 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)
@@ -778,9 +768,7 @@ int main(int argc, char *argv[])
}
}
else
- {
ci->badwords = NULL;
- }
}
*last = NULL;
}
@@ -790,7 +778,7 @@ int main(int argc, char *argv[])
ChannelInfo *ci;
- for (i = 0; i < 256; i++)
+ for (i = 0; i < 256; ++i)
{
for (ci = chanlists[i]; ci; ci = ci->next)
{
@@ -803,36 +791,32 @@ int main(int argc, char *argv[])
if (ci->successor)
fs << "MD SUCCESSOR " << ci->successor << std::endl;
fs << "MD LEVELS";
- for (j = 0; j < 36; j++)
+ 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;
+ 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)
@@ -844,28 +828,24 @@ int main(int argc, char *argv[])
if (ci->flags & CI_FORBIDDEN)
fs << "MD FORBID " << ci->forbidby << " :" << (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
+ 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;
- }
+ 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>
+ 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].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->akick[j].reason)
+ fs << ci->akick[j].reason;
+ fs << std::endl;
}
- }
if (ci->mlock_on)
{
@@ -894,9 +874,8 @@ int main(int argc, char *argv[])
}
if (ci->memos.memocount)
{
- Memo *memos;
- memos = ci->memos.memos;
- for (j = 0; j < ci->memos.memocount; j++, memos++)
+ 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)
@@ -915,20 +894,20 @@ int main(int argc, char *argv[])
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;
+ << (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];
@@ -949,18 +928,16 @@ int main(int argc, char *argv[])
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++)
- {
+ for (j = 0; j < ci->bwcount; ++j)
if (ci->badwords[j].in_use)
{
fs << "MD BI BADWORD "
- << (( ci->badwords[j].type == 0 ) ? "ANY " : "" )
- << (( ci->badwords[j].type == 1 ) ? "SINGLE " : "" )
- << (( ci->badwords[j].type == 2 ) ? "START " : "" )
- << (( ci->badwords[j].type == 3 ) ? "END " : "" )
+ << (!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) */
@@ -983,7 +960,7 @@ int main(int argc, char *argv[])
/* AKILLS */
read_int16(&capacity, f);
- for (i = 0; i < capacity; i++)
+ for (i = 0; i < capacity; ++i)
{
SAFE(read_string(&user, f));
SAFE(read_string(&host, f));
@@ -992,11 +969,14 @@ int main(int argc, char *argv[])
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);
+ delete [] user;
+ delete [] host;
+ delete [] by;
+ delete [] reason;
}
/* SNLINES */
read_int16(&capacity, f);
- for (i = 0; i < capacity; i++)
+ for (i = 0; i < capacity; ++i)
{
SAFE(read_string(&mask, f));
SAFE(read_string(&by, f));
@@ -1004,11 +984,13 @@ int main(int argc, char *argv[])
SAFE(read_int32(&seton, f));
SAFE(read_int32(&expires, f));
fs << "OS SNLINE " << mask << " " << by << " " << seton << " " << expires << " :" << reason << std::endl;
- free(mask); free(by); free(reason);
+ delete [] mask;
+ delete [] by;
+ delete [] reason;
}
/* SQLINES */
read_int16(&capacity, f);
- for (i = 0; i < capacity; i++)
+ for (i = 0; i < capacity; ++i)
{
SAFE(read_string(&mask, f));
SAFE(read_string(&by, f));
@@ -1016,11 +998,13 @@ int main(int argc, char *argv[])
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);
+ delete [] mask;
+ delete [] by;
+ delete [] reason;
}
/* SZLINES */
read_int16(&capacity, f);
- for (i = 0; i < capacity; i++)
+ for (i = 0; i < capacity; ++i)
{
SAFE(read_string(&mask, f));
SAFE(read_string(&by, f));
@@ -1028,12 +1012,13 @@ int main(int argc, char *argv[])
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);
+ delete [] mask;
+ delete [] by;
+ delete [] reason;
}
close_db(f);
} // operserv database
-
/* CONVERTING DONE \o/ HURRAY! */
fs.flush();
fs.close();
diff --git a/src/tools/db-convert.h b/src/tools/db-convert.h
index b3712eaf5..cf265c92f 100644
--- a/src/tools/db-convert.h
+++ b/src/tools/db-convert.h
@@ -14,12 +14,19 @@
* GNU General Public License for more details.
*/
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
+#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>
-#include <ctype.h>
-#include <time.h>
#ifndef _WIN32
#include <unistd.h>
@@ -29,10 +36,6 @@
#endif
#include "sysconf.h"
-#include <string>
-#include <iostream>
-#include <fstream>
-
#ifndef _WIN32
#define C_LBLUE "\033[1;34m"
#define C_NONE "\033[m"
@@ -41,156 +44,166 @@
#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) do { \
- if ((x) < 0) { \
- printf("Error, the database is broken, trying to continue... no guarantee.\n"); \
- } \
-} while (0)
-#define READ(x) do { \
- if ((x) < 0) { \
+#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); \
} \
-} while (0)
-
-typedef struct memo_ Memo;
-typedef struct dbFILE_ dbFILE;
-typedef struct nickalias_ NickAlias;
-typedef struct nickcore_ NickCore;
-typedef struct chaninfo_ ChannelInfo;
-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 */
+} \
+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 dbFILE
+{
+ 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 */
-} MemoInfo;
+struct MemoInfo
+{
+ int16 memocount; /* Current # of memos */
+ int16 memomax; /* Max # of memos one can hold*/
+ Memo *memos; /* Pointer to original memos */
+};
-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;
-} ChanAccess;
+struct NickCore
+{
+ NickCore *next, *prev;
-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 */
- 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;
-} AutoKick;
+ 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_ {
+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 *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 nickcore_ {
- NickCore *next, *prev;
+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;
+};
- 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 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 chaninfo_ {
+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 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 *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 */
+ 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_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 badword_ {
- uint16 in_use;
- char *word;
- uint16 type;
+ 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_ {
+struct HostCore
+{
HostCore *next;
char *nick;
char *vIdent;
@@ -199,7 +212,6 @@ struct hostcore_ {
int32 time;
};
-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);
@@ -230,94 +242,94 @@ HostCore *head = NULL;
int b64_encode(char *src, size_t srclength, char *target, size_t targsize);
/* 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 */
+#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 */
+#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_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
+#define CI_KEEPTOPIC 0x00000001
/* Don't allow non-authorized users to be opped */
-#define CI_SECUREOPS 0x00000002
+#define CI_SECUREOPS 0x00000002
/* Hide channel from ChanServ LIST command */
-#define CI_PRIVATE 0x00000004
+#define CI_PRIVATE 0x00000004
/* Topic can only be changed by SET TOPIC */
-#define CI_TOPICLOCK 0x00000008
+#define CI_TOPICLOCK 0x00000008
/* Those not allowed ops are kickbanned */
-#define CI_RESTRICTED 0x00000010
+#define CI_RESTRICTED 0x00000010
/* Don't allow ChanServ and BotServ commands to do bad things to bigger levels */
-#define CI_PEACE 0x00000020
+#define CI_PEACE 0x00000020
/* Don't allow any privileges unless a user is IDENTIFY'd with NickServ */
-#define CI_SECURE 0x00000040
+#define CI_SECURE 0x00000040
/* Don't allow the channel to be registered or used */
-#define CI_FORBIDDEN 0x00000080
+#define CI_FORBIDDEN 0x00000080
/* Channel password is encrypted */
-#define CI_ENCRYPTEDPW 0x00000100
+#define CI_ENCRYPTEDPW 0x00000100
/* Channel does not expire */
-#define CI_NO_EXPIRE 0x00000200
+#define CI_NO_EXPIRE 0x00000200
/* Channel memo limit may not be changed */
-#define CI_MEMO_HARDMAX 0x00000400
+#define CI_MEMO_HARDMAX 0x00000400
/* Send notice to channel on use of OP/DEOP */
-#define CI_OPNOTICE 0x00000800
+#define CI_OPNOTICE 0x00000800
/* Stricter control of channel founder status */
-#define CI_SECUREFOUNDER 0x00001000
+#define CI_SECUREFOUNDER 0x00001000
/* Always sign kicks */
-#define CI_SIGNKICK 0x00002000
+#define CI_SIGNKICK 0x00002000
/* Sign kicks if level is < than the one defined by the SIGNKICK level */
-#define CI_SIGNKICK_LEVEL 0x00004000
+#define CI_SIGNKICK_LEVEL 0x00004000
/* Use the xOP lists */
-#define CI_XOP 0x00008000
+#define CI_XOP 0x00008000
/* Channel is suspended */
-#define CI_SUSPENDED 0x00010000
+#define CI_SUSPENDED 0x00010000
/* akick */
-#define AK_USED 0x0001
-#define AK_ISNICK 0x0002
-#define AK_STUCK 0x0004
+#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
+#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
+#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
@@ -330,35 +342,38 @@ int b64_encode(char *src, size_t srclength, char *target, size_t targsize);
#define BS_KICK_REPEAT 0x01000000
/* Indices for TTB (Times To Ban) */
-#define TTB_BOLDS 0
-#define TTB_COLORS 1
-#define TTB_REVERSES 2
-#define TTB_UNDERLINES 3
-#define TTB_BADWORDS 4
-#define TTB_CAPS 5
-#define TTB_FLOOD 6
-#define TTB_REPEAT 7
-#define TTB_SIZE 8
-
-
-
-#define LANG_EN_US 0 /* United States English */
-#define LANG_JA_JIS 1 /* Japanese (JIS encoding) */
-#define LANG_JA_EUC 2 /* Japanese (EUC encoding) */
-#define LANG_JA_SJIS 3 /* Japanese (SJIS encoding) */
-#define LANG_ES 4 /* Spanish */
-#define LANG_PT 5 /* Portugese */
-#define LANG_FR 6 /* French */
-#define LANG_TR 7 /* Turkish */
-#define LANG_IT 8 /* Italian */
-#define LANG_DE 9 /* German */
-#define LANG_CAT 10 /* Catalan */
-#define LANG_GR 11 /* Greek */
-#define LANG_NL 12 /* Dutch */
-#define LANG_RU 13 /* Russian */
-#define LANG_HUN 14 /* Hungarian */
-#define LANG_PL 15 /* Polish */
+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)
{
@@ -420,80 +435,45 @@ dbFILE *open_db_read(const char *service, const char *filename, int version)
FILE *fp;
int myversion;
- f = (dbFILE *)calloc(sizeof(*f), 1);
- if (!f) {
+ 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) {
+ if (!fp)
+ {
printf("Can't read %s database %s.\n", service, f->filename);
- free(f);
+ //free(f);
+ delete f;
return NULL;
}
f->fp = fp;
myversion = fgetc(fp) << 24 | fgetc(fp) << 16 | fgetc(fp) << 8 | fgetc(fp);
- if (feof(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;
-}
-
-/* Open a database file for reading and check for the version */
-dbFILE *open_db_write(const char *service, const char *filename, int version)
-{
- dbFILE *f;
- int fd;
-
- f = (dbFILE *)calloc(sizeof(*f), 1);
- if (!f) {
- printf("Can't allocate memory for %s database %s.\n", service, filename);
+ else if (myversion < version)
+ {
+ printf("Unsuported database version (%d) on %s.\n", myversion, f->filename);
exit(0);
}
- strscpy(f->filename, filename, sizeof(f->filename));
- filename = f->filename;
-#ifndef _WIN32
- unlink(filename);
-#else
- DeleteFile(filename);
-#endif
- f->mode = 'w';
-#ifndef _WIN32
- fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0666);
-#else
- fd = _open(filename, O_WRONLY | O_CREAT | O_EXCL | _O_BINARY, 0666);
-#endif
- f->fp = fdopen(fd, "wb"); /* will fail and return NULL if fd < 0 */
- if (!f->fp || !write_file_version(f, version)) {
- printf("Can't write to %s database %s.\n", service, filename);
- if (f->fp) {
- fclose(f->fp);
-#ifndef _WIN32
- unlink(filename);
-#else
- DeleteFile(filename);
-#endif
- }
- free(f);
- return NULL;
- }
return f;
}
/* Close it */
-void close_db(dbFILE * f)
+void close_db(dbFILE *f)
{
fclose(f->fp);
- free(f);
+ delete f;
}
-int read_int16(int16 * ret, dbFILE * f)
+int read_int16(int16 *ret, dbFILE *f)
{
int c1, c2;
@@ -505,7 +485,7 @@ int read_int16(int16 * ret, dbFILE * f)
return 0;
}
-int read_uint16(uint16 * ret, dbFILE * f)
+int read_uint16(uint16 *ret, dbFILE *f)
{
int c1, c2;
@@ -517,16 +497,14 @@ int read_uint16(uint16 * ret, dbFILE * f)
return 0;
}
-
-int write_int16(uint16 val, dbFILE * f)
+int write_int16(uint16 val, dbFILE *f)
{
- if (fputc((val >> 8) & 0xFF, f->fp) == EOF
- || fputc(val & 0xFF, f->fp) == EOF)
+ 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 read_int32(int32 *ret, dbFILE *f)
{
int c1, c2, c3, c4;
@@ -540,7 +518,7 @@ int read_int32(int32 * ret, dbFILE * f)
return 0;
}
-int read_uint32(uint32 * ret, dbFILE * f)
+int read_uint32(uint32 *ret, dbFILE *f)
{
int c1, c2, c3, c4;
@@ -554,7 +532,7 @@ int read_uint32(uint32 * ret, dbFILE * f)
return 0;
}
-int write_int32(uint32 val, dbFILE * f)
+int write_int32(uint32 val, dbFILE *f)
{
if (fputc((val >> 24) & 0xFF, f->fp) == EOF)
return -1;
@@ -567,15 +545,14 @@ int write_int32(uint32 val, dbFILE * f)
return 0;
}
-
-int read_ptr(void **ret, dbFILE * f)
+int read_ptr(void **ret, dbFILE *f)
{
int c;
c = fgetc(f->fp);
if (c == EOF)
return -1;
- *ret = (c ? (void *) 1 : (void *) 0);
+ *ret = c ? reinterpret_cast<void *>(1) : reinterpret_cast<void *>(0);
return 0;
}
@@ -586,28 +563,29 @@ int write_ptr(const void *ptr, dbFILE * f)
return 0;
}
-
-int read_string(char **ret, dbFILE * f)
+int read_string(char **ret, dbFILE *f)
{
char *s;
uint16 len;
if (read_uint16(&len, f) < 0)
return -1;
- if (len == 0) {
+ if (len == 0)
+ {
*ret = NULL;
return 0;
}
- s = (char *)calloc(len, 1);
- if (len != fread(s, 1, len, f->fp)) {
- free(s);
+ 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)
+int write_string(const char *s, dbFILE *f)
{
uint32 len;
@@ -616,7 +594,7 @@ int write_string(const char *s, dbFILE * f)
len = strlen(s);
if (len > 65534)
len = 65534;
- if (write_int16((uint16) (len + 1), f) < 0)
+ if (write_int16(static_cast<uint16>(len + 1), f) < 0)
return -1;
if (len > 0 && fwrite(s, 1, len, f->fp) != len)
return -1;
@@ -629,11 +607,9 @@ NickCore *findcore(const char *nick, int unused)
{
NickCore *nc;
- for (nc = nclists[HASH(nick)]; nc; nc = nc->next) {
- if (!mystricmp(nc->display, nick))
- if ((nc->unused && unused) || (!nc->unused && !unused))
- return 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;
}
@@ -642,23 +618,20 @@ NickAlias *findnick(const char *nick)
{
NickAlias *na;
- for (na = nalists[HASH(nick)]; na; na = na->next) {
+ 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)
+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);
+ 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;
}
@@ -682,11 +655,12 @@ int mystricmp(const char *s1, const char *s2)
{
register int c;
- while ((c = tolower(*s1)) == tolower(*s2)) {
- if (c == 0)
+ while ((c = tolower(*s1)) == tolower(*s2))
+ {
+ if (!c)
return 0;
- s1++;
- s2++;
+ ++s1;
+ ++s2;
}
if (c < tolower(*s2))
return -1;
@@ -695,7 +669,8 @@ int mystricmp(const char *s1, const char *s2)
int delnick(NickAlias *na, int donttouchthelist)
{
- if (!donttouchthelist) {
+ if (!donttouchthelist)
+ {
/* Remove us from the aliases list */
if (na->next)
na->next->prev = na->prev;
@@ -706,14 +681,14 @@ int delnick(NickAlias *na, int donttouchthelist)
}
if (na->last_usermask)
- free(na->last_usermask);
+ delete [] na->last_usermask;
if (na->last_realname)
- free(na->last_realname);
+ delete [] na->last_realname;
if (na->last_quit)
- free(na->last_quit);
+ delete [] na->last_quit;
/* free() us */
- free(na->nick);
- free(na);
+ delete [] na->nick;
+ delete na;
return 1;
}
@@ -728,52 +703,48 @@ int delcore(NickCore *nc)
else
nclists[HASH(nc->display)] = nc->next;
- free(nc->display);
+ delete [] nc->display;
if (nc->pass)
- free(nc->pass);
+ delete [] nc->pass;
if (nc->email)
- free(nc->email);
+ delete [] nc->email;
if (nc->greet)
- free(nc->greet);
+ delete [] nc->greet;
if (nc->url)
- free(nc->url);
- if (nc->access) {
- for (i = 0; i < nc->accesscount; i++) {
+ delete [] nc->url;
+ if (nc->access)
+ {
+ for (i = 0; i < nc->accesscount; ++i)
if (nc->access[i])
- free(nc->access[i]);
- }
- free(nc->access);
+ delete [] nc->access[i];
+ delete [] nc->access;
}
- if (nc->memos.memos) {
- for (i = 0; i < nc->memos.memocount; i++) {
+ if (nc->memos.memos)
+ {
+ for (i = 0; i < nc->memos.memocount; ++i)
if (nc->memos.memos[i].text)
- free(nc->memos.memos[i].text);
- }
- free(nc->memos.memos);
+ delete [] nc->memos.memos[i].text;
+ delete [] nc->memos.memos;
}
- free(nc);
+ delete nc;
return 1;
}
-
ChannelInfo *cs_findchan(const char *chan)
{
ChannelInfo *ci;
- for (ci = chanlists[tolower(chan[1])]; ci; ci = ci->next) {
+ 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)
+void alpha_insert_chan(ChannelInfo *ci)
{
ChannelInfo *ptr, *prev;
char *chan = ci->name;
- for (prev = NULL, ptr = chanlists[tolower(chan[1])];
- ptr != NULL && mystricmp(ptr->name, chan) < 0;
- prev = ptr, ptr = ptr->next);
+ 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)
@@ -787,24 +758,22 @@ void alpha_insert_chan(ChannelInfo * 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)
+const char *base64enc(long i)
{
if (i < 0)
- return ("0");
+ return "0";
return int_to_base64(i);
}
-long base64dec(char* b64)
+long base64dec(char *b64)
{
if (b64)
return base64_to_int(b64);
@@ -812,9 +781,7 @@ long base64dec(char* b64)
return 0;
}
-
-static const char Base64[] =
- "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+static const char Base64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const char Pad64 = '=';
/* (From RFC1521 and draft-ietf-dnssec-secext-03.txt)
@@ -887,7 +854,8 @@ int b64_encode(char *src, size_t srclength, char *target, size_t targsize)
unsigned char output[4];
size_t i;
- while (2 < srclength) {
+ while (srclength > 2)
+ {
input[0] = *src++;
input[1] = *src++;
input[2] = *src++;
@@ -899,7 +867,7 @@ int b64_encode(char *src, size_t srclength, char *target, size_t targsize)
output[3] = input[2] & 0x3f;
if (datalength + 4 > targsize)
- return (-1);
+ return -1;
target[datalength++] = Base64[output[0]];
target[datalength++] = Base64[output[1]];
target[datalength++] = Base64[output[2]];
@@ -907,10 +875,11 @@ int b64_encode(char *src, size_t srclength, char *target, size_t targsize)
}
/* Now we worry about padding. */
- if (0 != srclength) {
+ if (srclength)
+ {
/* Get what's left. */
input[0] = input[1] = input[2] = '\0';
- for (i = 0; i < srclength; i++)
+ for (i = 0; i < srclength; ++i)
input[i] = *src++;
output[0] = input[0] >> 2;
@@ -918,7 +887,7 @@ int b64_encode(char *src, size_t srclength, char *target, size_t targsize)
output[2] = ((input[1] & 0x0f) << 2) + (input[2] >> 6);
if (datalength + 4 > targsize)
- return (-1);
+ return -1;
target[datalength++] = Base64[output[0]];
target[datalength++] = Base64[output[1]];
if (srclength == 1)
@@ -928,9 +897,9 @@ int b64_encode(char *src, size_t srclength, char *target, size_t targsize)
target[datalength++] = Pad64;
}
if (datalength >= targsize)
- return (-1);
+ return -1;
target[datalength] = '\0'; /* Returned value doesn't count \0. */
- return (datalength);
+ return datalength;
}
/* skips all whitespace anywhere.
@@ -942,64 +911,68 @@ int b64_encode(char *src, size_t srclength, char *target, size_t targsize)
int b64_decode(const char *src, char *target, size_t targsize)
{
int tarindex, state, ch;
- char *pos;
+ const char *pos;
state = 0;
tarindex = 0;
- while ((ch = *src++) != '\0') {
- if (isspace(ch)) /* Skip whitespace anywhere. */
+ while ((ch = *src++))
+ {
+ if (isspace(ch)) /* Skip whitespace anywhere. */
continue;
if (ch == Pad64)
break;
- pos = const_cast<char *>(strchr(Base64, ch));
- if (pos == 0) /* A non-base64 character. */
- return (-1);
-
- switch (state) {
- case 0:
- if (target) {
- if ((size_t) tarindex >= targsize)
- return (-1);
- target[tarindex] = (pos - Base64) << 2;
- }
- state = 1;
- break;
- case 1:
- if (target) {
- if ((size_t) tarindex + 1 >= targsize)
- return (-1);
- target[tarindex] |= (pos - Base64) >> 4;
- target[tarindex + 1] = ((pos - Base64) & 0x0f)
- << 4;
- }
- tarindex++;
- state = 2;
- break;
- case 2:
- if (target) {
- if ((size_t) tarindex + 1 >= targsize)
- return (-1);
- target[tarindex] |= (pos - Base64) >> 2;
- target[tarindex + 1] = ((pos - Base64) & 0x03)
- << 6;
- }
- tarindex++;
- state = 3;
- break;
- case 3:
- if (target) {
- if ((size_t) tarindex >= targsize)
- return (-1);
- target[tarindex] |= (pos - Base64);
- }
- tarindex++;
- state = 0;
- break;
- default:
- abort();
+ pos = strchr(Base64, ch);
+ if (!pos) /* A non-base64 character. */
+ return -1;
+
+ switch (state)
+ {
+ case 0:
+ if (target)
+ {
+ if (static_cast<size_t>(tarindex) >= targsize)
+ return -1;
+ target[tarindex] = (pos - Base64) << 2;
+ }
+ state = 1;
+ break;
+ case 1:
+ if (target)
+ {
+ if (static_cast<size_t>(tarindex) + 1 >= targsize)
+ return -1;
+ target[tarindex] |= (pos - Base64) >> 4;
+ target[tarindex + 1] = ((pos - Base64) & 0x0f) << 4;
+ }
+ ++tarindex;
+ state = 2;
+ break;
+ case 2:
+ if (target)
+ {
+ if (static_cast<size_t>(tarindex) + 1 >= targsize)
+ return -1;
+ target[tarindex] |= (pos - Base64) >> 2;
+ target[tarindex + 1] = ((pos - Base64) & 0x03) << 6;
+ }
+ ++tarindex;
+ state = 3;
+ break;
+ case 3:
+ if (target)
+ {
+ if (static_cast<size_t>(tarindex) >= targsize)
+ return (-1);
+ target[tarindex] |= pos - Base64;
+ }
+ ++tarindex;
+ state = 0;
+ break;
+ default:
+ abort();
}
}
@@ -1008,53 +981,57 @@ int b64_decode(const char *src, char *target, size_t targsize)
* on a byte boundary, and/or with erroneous trailing characters.
*/
- if (ch == Pad64) { /* We got a pad char. */
- ch = *src++; /* Skip it, get next. */
- switch (state) {
- case 0: /* Invalid = in first position */
- case 1: /* Invalid = in second position */
- return (-1);
-
- case 2: /* Valid, means one byte of info */
- /* Skip any number of spaces. */
- for (; ch != '\0'; ch = *src++)
- if (!isspace(ch))
- break;
- /* Make sure there is another trailing = sign. */
- if (ch != Pad64)
- return (-1);
- ch = *src++; /* Skip the = */
- /* Fall through to "single trailing =" case. */
- /* FALLTHROUGH */
-
- case 3: /* Valid, means two bytes of info */
- /*
- * We know this char is an =. Is there anything but
- * whitespace after it?
- */
- for (; ch != '\0'; ch = *src++)
- if (!isspace(ch))
- return (-1);
-
- /*
- * Now make sure for cases 2 and 3 that the "extra"
- * bits that slopped past the last full byte were
- * zeros. If we don't check them, they become a
- * subliminal channel.
- */
- if (target && target[tarindex] != 0)
+ if (ch == Pad64) /* We got a pad char. */
+ {
+ ch = *src++; /* Skip it, get next. */
+ switch (state)
+ {
+ case 0: /* Invalid = in first position */
+ case 1: /* Invalid = in second position */
return (-1);
+
+ case 2: /* Valid, means one byte of info */
+ /* Skip any number of spaces. */
+ for (; ch != '\0'; ch = *src++)
+ if (!isspace(ch))
+ break;
+ /* Make sure there is another trailing = sign. */
+ if (ch != Pad64)
+ return -1;
+ ch = *src++; /* Skip the = */
+ /* Fall through to "single trailing =" case. */
+ /* FALLTHROUGH */
+
+ case 3: /* Valid, means two bytes of info */
+ /*
+ * We know this char is an =. Is there anything but
+ * whitespace after it?
+ */
+ for (; ch != '\0'; ch = *src++)
+ if (!isspace(ch))
+ return (-1);
+
+ /*
+ * Now make sure for cases 2 and 3 that the "extra"
+ * bits that slopped past the last full byte were
+ * zeros. If we don't check them, they become a
+ * subliminal channel.
+ */
+ if (target && target[tarindex])
+ return -1;
}
- } else {
+ }
+ else
+ {
/*
* We ended by seeing the end of the string. Make sure we
* have no partial bytes lying around.
*/
- if (state != 0)
- return (-1);
+ if (state)
+ return -1;
}
- return (tarindex);
+ return tarindex;
}
/* ':' and '#' and '&' and '+' and '@' must never be in this table. */
@@ -1104,11 +1081,11 @@ static char *int_to_base64(long val)
* if the value is then too large it can easily lead to
* a buffer underflow and thus to a crash. -- Syzop
*/
- if (val > 2147483647L) {
+ if (val > 2147483647L)
abort();
- }
- do {
+ do
+ {
base64buf[--i] = int6_to_base64_map[val & 63];
}
while (val >>= 6);
@@ -1118,30 +1095,18 @@ static char *int_to_base64(long val)
static long base64_to_int(char *b64)
{
- int v = base64_to_int6_map[(unsigned char) *b64++];
+ int v = base64_to_int6_map[static_cast<unsigned char>(*b64++)];
if (!b64)
return 0;
- while (*b64) {
+ while (*b64)
+ {
v <<= 6;
- v += base64_to_int6_map[(unsigned char) *b64++];
+ v += base64_to_int6_map[static_cast<unsigned char>(*b64++)];
}
return v;
}
-int stricmp(const char *s1, const char *s2)
-{
- register int c;
-
- while ((c = tolower(*s1)) == tolower(*s2)) {
- if (c == 0)
- return 0;
- s1++;
- s2++;
- }
- if (c < tolower(*s2))
- return -1;
- return 1;
-}
+#endif // DB_CONVERT_H
diff --git a/src/tools/smtp.h b/src/tools/smtp.h
index 1dc73eb6f..9f7140537 100644
--- a/src/tools/smtp.h
+++ b/src/tools/smtp.h
@@ -1,5 +1,4 @@
/*
- *
* (C) 2003-2010 Anope Team
* Contact us at team@anope.org
*
@@ -7,27 +6,29 @@
*
* Based on the original code of Epona by Lara.
* Based on the original code of Services by Andy Church.
- *
- *
*/
#ifndef SMTP_H
#define SMTP_H
#include "sysconf.h"
+#define CoreExport
+#include "hashcomp.h"
/*************************************************************************/
/* Some Linux boxes (or maybe glibc includes) require this for the
* prototype of strsignal(). */
#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
+# define _GNU_SOURCE
#endif
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <string>
+#include <vector>
+#include <cstdarg>
+#include <cstdio>
+#include <ctime>
+#include <cerrno>
/* Windows does not have:
* unistd.h, grp.h,
@@ -39,34 +40,30 @@
*/
#ifndef _WIN32
-#include <unistd.h>
+# include <unistd.h>
#endif
-#include <signal.h>
-#include <time.h>
-#include <errno.h>
-#include <limits.h>
-
#ifndef _WIN32
-#include <netdb.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
-#include <arpa/inet.h>
+# include <netdb.h>
+# include <netinet/in.h>
+# include <sys/socket.h>
+# include <arpa/inet.h>
#else
-#include <winsock.h>
-#include <windows.h>
+# include <winsock.h>
+# define WIN32_LEAN_AND_MEAN
+# include <windows.h>
#endif
#include <sys/types.h>
#ifndef _WIN32
-#include <sys/time.h>
+# include <sys/time.h>
#endif
#ifdef _AIX
extern int strcasecmp(const char *, const char *);
extern int strncasecmp(const char *, const char *, size_t);
-# if 0 /* These break on some AIX boxes (4.3.1 reported). */
+# if 0 /* These break on some AIX boxes (4.3.1 reported). */
extern int socket(int, int, int);
extern int connect(int, struct sockaddr *, int);
# endif
@@ -77,52 +74,32 @@ extern int connect(int, struct sockaddr *, int);
/* Solaris specific code, types that do not exist in Solaris'
* * sys/types.h
* **/
-#ifndef INADDR_NONE
-#define INADDR_NONE (-1)
-#endif
-
+# ifndef INADDR_NONE
+# define INADDR_NONE (-1)
+# endif
#endif
-
-/*#ifdef _WIN32
-#define PATH_MAX MAX_PATH
-#define snprintf _snprintf
-#endif*/
-
-
/*************************************************************************/
#ifdef _WIN32
-#include <winsock.h>
-typedef SOCKET ano_socket_t;
-#define ano_sockclose(fd) closesocket(fd)
-#define ano_sockread(fd, buf, len) recv(fd, buf, len, 0)
-#define ano_sockwrite(fd, buf, len) send(fd, buf, len, 0)
+typedef SOCKET ano_socket_t;
+#define ano_sockclose(fd) closesocket(fd)
+#define ano_sockread(fd, buf, len) recv(fd, buf, len, 0)
+#define ano_sockwrite(fd, buf, len) send(fd, buf, len, 0)
#else
-typedef int ano_socket_t;
-#define ano_sockclose(fd) close(fd)
-#define ano_sockread(fd, buf, len) read(fd, buf, len)
-#define ano_sockwrite(fd, buf, len) write(fd, buf, len)
+typedef int ano_socket_t;
+#define ano_sockclose(fd) close(fd)
+#define ano_sockread(fd, buf, len) read(fd, buf, len)
+#define ano_sockwrite(fd, buf, len) write(fd, buf, len)
#define SOCKET_ERROR -1
#endif
-
/* Data structures */
-struct smtp_header {
- char *header;
- struct smtp_header *next;
-};
-
-struct smtp_body_line {
- char *line;
- struct smtp_body_line *next;
-};
-
-struct smtp_message {
- struct smtp_header *smtp_headers, *smtp_headers_tail;
- struct smtp_body_line *smtp_body, *smtp_body_tail;
- char *from;
- char *to;
+struct smtp_message
+{
+ std::vector<ci::string> smtp_headers;
+ std::vector<ci::string> smtp_body;
+ ci::string from, to;
ano_socket_t sock;
};
@@ -131,4 +108,4 @@ struct smtp_message mail;
/* set this to 1 if you want to get a log otherwise it runs silent */
int smtp_debug = 0;
-#endif /* SMTP_H */
+#endif /* SMTP_H */