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;