src/module_commands.c \
src/ModuleFunctions.c \
src/statistics.c \
+ src/log.c \
src/memoryDebug.c
neonserv_LDADD = $(MYSQL_LIBS) $(SYSTEM_LIBS)
"port" = 7499;
"pass" = "blaa";
};
-"log" { //neonserv.log
+"logs" {
/*
- 1 - INFO
- 2 - ERROR
- 4 - RAW
- 8 - MYSQL
+ module:section = target_type:target
+ possible sections:
+ "info","debug","raw","mysql","override","warning","error","fatal"
+ possible targets:
+ file:log.log
+ irc:#channel
+ std:out
+ std:err
*/
- "loglevel" = 3;
+ "*:info,warning,error,fatal" = "file:neonserv.log";
+ // "*:override,error,fatal" = "irc:#neonserv";
+ "*:info" = "std:out";
};
"modules" {
"libglobalcmd" {
#include "ModeNode.h"
#include "IRCEvents.h"
#include "tools.h"
+#include "log.h"
static struct ChanNode **chanList;
struct ChanNode *chan = malloc(sizeof(*chan));
if (!chan)
{
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return NULL;
}
strcpy(chan->name, name);
#include "ChanNode.h"
#include "ModeNode.h"
#include "UserNode.h"
+#include "log.h"
struct ChanUser* addChanUser(struct ChanNode *chan, struct UserNode *user) {
struct ChanUser *chanuser = malloc(sizeof(*chanuser));
if (!chanuser)
{
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return NULL;
}
chanuser->flags = 0;
struct ChanUser *chanuser = malloc(sizeof(*chanuser));
if (!chanuser)
{
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return NULL;
}
chanuser->flags = CHANUSERFLAG_INVISIBLE;
#include "version.h"
#include "IOHandler.h"
#include "IRCEvents.h"
+#include "log.h"
struct socket_list {
struct ClientSocket *data;
sockets = malloc(sizeof(*sockets));
if (!sockets)
{
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
sockets->data = NULL;
if(!(client && (client->flags & SOCKET_FLAG_CONNECTED))) return 0;
SYNCHRONIZE(synchronized);
#ifdef HAVE_THREADS
- putlog(LOGLEVEL_RAW, "[%d send %d] %s", getCurrentThreadID(), len, msg);
+ printf_log("main", LOG_IRCRAW, "[%d send %d] %s", getCurrentThreadID(), len, msg);
#else
- putlog(LOGLEVEL_RAW, "[send %d] %s", len, msg);
+ printf_log("main", LOG_IRCRAW, "[send %d] %s", len, msg);
#endif
iohandler_send(client->iofd, msg, len);
client->traffic_out += len;
#include "ClientSocket.h"
#include "bots.h"
#include "ConfigParser.h"
+#include "log.h"
void _loadUserSettings(struct UserNode *user) {
SYNCHRONIZE(cache_sync);
if ((row = mysql_fetch_row(res)) != NULL) {
struct event_user_registered_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->user = user;
#include "UserNode.h"
#include "ChanNode.h"
#include "DBHelper.h"
+#include "log.h"
static struct Event *first_event = NULL, *last_event = NULL;
struct Event *event = malloc(sizeof(*event));
if (!event)
{
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return NULL;
}
event->client = client;
#include "IRCEvents.h"
#include "tools.h"
#include "modules.h"
+#include "log.h"
#define AUTHSERV_NICK "AuthServ"
struct HandleInfoQueueEntry *entry = malloc(sizeof(*entry));
if (!entry)
{
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return NULL;
}
SYNCHRONIZE(cache_sync);
#include "ChanUser.h"
#include "ClientSocket.h"
#include "mysqlConn.h"
+#include "log.h"
struct binding {
void *func;
if(!is_bound(TYPE, func)) { \
struct binding *cbind = malloc(sizeof(*cbind)); \
if (!cbind) { \
- perror("malloc() failed"); \
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__); \
return 0; \
} \
cbind->func = func; \
#include "timeq.h"
#include "ConfigParser.h"
#include "statistics.h"
+#include "log.h"
struct irc_cmd *irc_commands = NULL;
//static struct UserNode *registering_users = NULL;
int argc = 0;
char *argv[MAXNUMPARAMS];
#ifdef HAVE_THREADS
- putlog(LOGLEVEL_RAW, "[%d recv %lu] %s\n", getCurrentThreadID(), (unsigned long) strlen(line), line);
+ printf_log("main", LOG_IRCRAW, "[%d recv %lu] %s\n", getCurrentThreadID(), (unsigned long) strlen(line), line);
#else
- putlog(LOGLEVEL_RAW, "[recv %lu] %s\n", (unsigned long) strlen(line), line);
+ printf_log("main", LOG_IRCRAW, "[recv %lu] %s\n", (unsigned long) strlen(line), line);
#endif
if(line[0] == ':')
line++;
struct irc_cmd *irc_cmd = malloc(sizeof(*irc_cmd));
if (!irc_cmd)
{
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
irc_cmd->cmd = command;
if(!irc_cmd) {
event_raw(client, from, cmd, argv, argc);
} else if(!ret) {
- fprintf(stderr,"PARSE ERROR: %s\n", cmd);
+ printf_log("main", LOG_WARNING | LOG_IRCRAW, "PARSE ERROR: %s\n", cmd);
}
}
}
if(chanuser->visCount > chan->botcount) {
+ printf_log("main", LOG_WARNING, "visCount (%d) bigger than botcount (%d) on channel %s (user %s).", chanuser->visCount, chan->botcount, chan->name, user->nick);
chanuser->visCount = chan->botcount;
- //TODO: Trigger WARNING
}
//if multiple bots see the user, it can't be invisible
if(bot == client) continue;
if(!bot->network_name) continue;
if(stricmp(bot->network_name, value)) {
- putlog(LOGLEVEL_ERROR, "WARNING: Network name '%s' (%s) differs from '%s' (%s)! Connecting to multiple IRC-Networks with one instance is NOT supported!\n", client->network_name, client->nick, bot->network_name, bot->nick);
+ printf_log("main", LOG_ERROR, "WARNING: Network name '%s' (%s) differs from '%s' (%s)! Connecting to multiple IRC-Networks with one instance is NOT supported!\n", client->network_name, client->nick, bot->network_name, bot->nick);
break;
}
}
#include "ClientSocket.h"
#include "IOHandler.h"
#include "tools.h"
+#include "log.h"
#define MAXPENALTY 8 /* 4 messages */
static struct BotQueue *initialize_queue(struct ClientSocket *client) {
struct BotQueue *queue = malloc(sizeof(*queue));
if (!queue) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return NULL;
}
queue->client = client;
} else {
struct QueueEntry *entry = malloc(sizeof(*entry));
if (!entry) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return 0;
}
entry->msg = strdup(msg);
#include "ChanUser.h"
#include "UserNode.h"
#include "BanNode.h"
+#include "log.h"
static int modes_with_strarg, modes_with_intarg, modes_count;
struct ModeNode *modes = malloc(sizeof(*modes));
if (!modes)
{
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return NULL;
}
modes->chan = chan;
#include "tools.h"
#include "IRCEvents.h"
#include "IPNode.h"
+#include "log.h"
static struct UserNode **userList;
struct UserNode *user = malloc(sizeof(*user));
if (!user)
{
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return NULL;
}
strcpy(user->nick, nick);
if(!user) {
user = malloc(sizeof(*user));
if (!user) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return NULL;
}
user->ident[0] = 0;
if(!user) {
user = malloc(sizeof(*user));
if (!user) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return NULL;
}
user->ident[0] = 0;
user = malloc(sizeof(*user));
if (!user)
{
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return NULL;
}
strcpy(user->host, cmask);
user = malloc(sizeof(*user));
if (!user)
{
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return NULL;
}
strcpy(user->nick, cmask);
#include "ClientSocket.h"
#include "IPNode.h"
#include "modules.h"
+#include "log.h"
#define WHOQUEUETYPE_ISONQUEUE 0x01
#define WHOQUEUETYPE_USERLIST 0x02
struct WHOQueueEntry *entry = malloc(sizeof(*entry));
if (!entry)
{
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
DESYNCHRONIZE(whohandler_sync);
return NULL;
}
#include "DBHelper.h"
#include "IRCEvents.h"
#include "tools.h"
+#include "log.h"
struct cmd_bot_alias {
int botid;
}
botalias = malloc(sizeof(*botalias));
if (!botalias) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
botalias->botid = botid;
#include "DBHelper.h"
#include "mysqlConn.h"
#include "tools.h"
+#include "log.h"
#define DEFAULT_LANG_TAG "EN"
#define DEFAULT_LANG_NAME "English"
if(cindex == MAXLANGUAGES) return NULL;
struct language *lang = malloc(sizeof(*lang));
if (!lang) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return NULL;
}
lang->langtag = strdup(langtag);
if(!lang_entry) {
lang_entry = malloc(sizeof(*lang_entry));
if (!lang_entry) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
lang_entry->ident = strdup(ident);
if(buffer == NULL) {
buffer = (char *)malloc((MAXLEN+1) * sizeof(char));
if (!buffer) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return NULL;
}
}
--- /dev/null
+/* log.c - NeonServ v5.6
+ * Copyright (C) 2011-2012 Philipp Kreil (pk910)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "log.h"
+#include "ChanNode.h"
+#include "IRCEvents.h"
+#include "ClientSocket.h"
+#include "bots.h"
+#include "IOHandler.h"
+#include "tools.h"
+#include "ConfigParser.h"
+
+#define MAXLOGLEN 1024
+
+static void write_log(const char *module, const int section, const char *line, int len);
+static void load_log_targets();
+static void unload_log_targets();
+static int reload_log_targets(int init);
+
+
+#define LOG_TARGET_TYPE_FILE 1
+#define LOG_TARGET_TYPE_STDOUT 2
+#define LOG_TARGET_TYPE_STDERR 3
+#define LOG_TARGET_TYPE_IRC 4
+
+static const struct {
+ int id;
+ char *name;
+} log_sections[] = {
+ {LOG_INFO, "info"},
+ {LOG_DEBUG, "debug"},
+ {LOG_IRCRAW, "raw"},
+ {LOG_MYSQL, "mysql"},
+ {LOG_OVERRIDE, "override"},
+ {LOG_WARNING, "warning"},
+ {LOG_ERROR, "error"},
+ {LOG_FATAL, "fatal"},
+ {0, NULL}
+};
+
+struct log_target {
+ char *module;
+ int section;
+ int type : 8;
+ union {
+ char *channel;
+ FILE *fptr;
+ } target;
+ struct log_target *next;
+};
+
+static struct log_target *log_targets = NULL;
+
+static char *get_section_name(int section_id) {
+ int i = -1;
+ while(log_sections[++i].id) {
+ if(log_sections[i].id == section_id)
+ return log_sections[i].name;
+ }
+ return NULL;
+}
+
+static int get_section_id(char *section_name) {
+ int i = -1;
+ while(log_sections[++i].id) {
+ if(!stricmp(log_sections[i].name, section_name))
+ return log_sections[i].id;
+ }
+ return 0;
+}
+
+
+void printf_log(const char *module, const int section, const char *text, ...) {
+ va_list arg_list;
+ char logBuf[MAXLOGLEN];
+ int pos;
+ logBuf[0] = '\0';
+ va_start(arg_list, text);
+ pos = vsnprintf(logBuf, MAXLOGLEN - 1, text, arg_list);
+ va_end(arg_list);
+ if (pos < 0 || pos > (MAXLOGLEN - 1)) pos = MAXLOGLEN - 1;
+ logBuf[pos] = '\0';
+ write_log(module, section, logBuf, pos);
+}
+
+static void write_log(const char *module, const int section, const char *line, int len) {
+ if(!log_targets)
+ return;
+ SYNCHRONIZE(log_sync);
+ struct log_target *target;
+ char lineBuf[MAXLOGLEN];
+ char timeBuf[80];
+ int lineBufPos, timeBufPos;
+ time_t rawtime;
+ struct tm *timeinfo;
+ int i, j;
+
+ time(&rawtime);
+ timeinfo = localtime(&rawtime);
+ timeBufPos = strftime(timeBuf, 80, "[%X %x] ", timeinfo);
+
+ lineBufPos = sprintf(lineBuf, "(%s:", module);
+ for(i = 0, j = 0; i < LOG_SECTIONS; i++) {
+ if((section & (1 << i))) {
+ char *section_name = get_section_name((1 << i));
+ if(!section_name)
+ continue;
+ if(j++)
+ lineBuf[lineBufPos++] = ',';
+ lineBufPos += sprintf(lineBuf + lineBufPos, "%s", section_name);
+ }
+ }
+ lineBufPos += sprintf(lineBuf + lineBufPos, ") %s", line);
+ //cut off \n \r
+ while(lineBuf[lineBufPos-1] == '\r' || lineBuf[lineBufPos-1] == '\n') {
+ lineBuf[lineBufPos-1] = '\0';
+ lineBufPos--;
+ }
+
+ j = 0;
+ for(target = log_targets; target; target = target->next) {
+ if(strcmp(target->module, "*") && stricmp(target->module, module))
+ continue;
+ if(!(target->section & section))
+ continue;
+ if(target->type == LOG_TARGET_TYPE_IRC) {
+ if(section == LOG_IRCRAW || (!stricmp(module, "iohandler") && section == LOG_DEBUG))
+ continue; //endless loop ;)
+ struct ChanNode *channel = getChanByName(target->target.channel);
+ struct ClientSocket *client;
+ if(channel && (client = getChannelBot(channel, 0))) {
+ putsock(client, "PRIVMSG %s :%s", channel->name, lineBuf);
+ }
+ } else if(target->type == LOG_TARGET_TYPE_FILE) {
+ fwrite(timeBuf, 1, timeBufPos, target->target.fptr);
+ fwrite(lineBuf, 1, lineBufPos, target->target.fptr);
+ fwrite("\n", 1, 1, target->target.fptr);
+ } else if(target->type == LOG_TARGET_TYPE_STDOUT || target->type == LOG_TARGET_TYPE_STDERR) {
+ if(process_state.daemonized)
+ continue; //block stdout / stderr as daemon
+ fprintf((target->type == LOG_TARGET_TYPE_STDOUT ? stdout : stderr), "%s%s\n", timeBuf, lineBuf);
+ j = 1;
+ }
+ }
+ if((process_state.loglevel & section) && !process_state.daemonized && !j) {
+ fprintf(stdout, "%s%s\n", timeBuf, lineBuf);
+ }
+
+ DESYNCHRONIZE(log_sync);
+}
+
+static void load_log_targets() {
+ if(log_targets)
+ return;
+ char **targetlist = get_all_fieldnames("logs");
+ if(!targetlist) return;
+ int i = 0;
+ char tmp[MAXLEN];
+ struct log_target *ctarget;
+ while(targetlist[i]) {
+ sprintf(tmp, "logs.%s", targetlist[i]);
+ char *type = get_string_field(tmp);
+ char *target = strchr(type, ':');
+ char *module = targetlist[i];
+ char *section = strchr(module, ':');
+ if(!target || !section) {
+ i++;
+ continue;
+ }
+ *target = '\0';
+ target++;
+ *section = '\0';
+ section++;
+ ctarget = malloc(sizeof(*ctarget));
+ if(!stricmp(type, "file")) {
+ ctarget->type = LOG_TARGET_TYPE_FILE;
+ ctarget->target.fptr = fopen(target, "a");
+ if(!ctarget->target.fptr) {
+ free(ctarget);
+ ctarget = NULL;
+ }
+ } else if(!stricmp(type, "std")) {
+ if(!stricmp(target, "out"))
+ ctarget->type = LOG_TARGET_TYPE_STDOUT;
+ else if(!stricmp(target, "err"))
+ ctarget->type = LOG_TARGET_TYPE_STDERR;
+ else {
+ free(ctarget);
+ ctarget = NULL;
+ }
+ } else if(!stricmp(type, "irc")) {
+ if(is_valid_chan(target)) {
+ ctarget->type = LOG_TARGET_TYPE_IRC;
+ ctarget->target.channel = strdup(target);
+ } else {
+ free(ctarget);
+ ctarget = NULL;
+ }
+ } else {
+ free(ctarget);
+ ctarget = NULL;
+ }
+ if(ctarget) {
+ ctarget->module = strdup(module);
+ ctarget->section = 0;
+ char *csection = section;
+ while(1) {
+ char *next_section = strchr(csection, ',');
+ if(next_section)
+ *next_section = '\0';
+ if(!strcmp(csection, "*"))
+ ctarget->section |= LOG_ALL;
+ else
+ ctarget->section |= get_section_id(csection);
+ if(next_section) {
+ *next_section = ',';
+ csection = next_section + 1;
+ } else
+ break;
+ }
+ ctarget->next = log_targets;
+ log_targets = ctarget;
+ }
+ target--;
+ *target = ':';
+ section--;
+ *section = ':';
+ i++;
+ }
+}
+
+static void unload_log_targets() {
+ struct log_target *target, *next_target;
+ for(target = log_targets; target; target = next_target) {
+ next_target = target->next;
+ if(target->type == LOG_TARGET_TYPE_IRC)
+ free(target->target.channel);
+ else if(target->type == LOG_TARGET_TYPE_FILE)
+ fclose(target->target.fptr);
+ free(target);
+ }
+ log_targets = NULL;
+}
+
+static int reload_log_targets(int init) {
+ unload_log_targets();
+ load_log_targets();
+ return 1;
+}
+
+static IOHANDLER_LOG_BACKEND(log_iohandler_backend) {
+ int log_level;
+ switch(type) {
+ case IOLOG_DEBUG:
+ log_level = LOG_DEBUG;
+ break;
+ case IOLOG_WARNING:
+ log_level = LOG_WARNING;
+ break;
+ case IOLOG_ERROR:
+ log_level = LOG_ERROR;
+ break;
+ case IOLOG_FATAL:
+ log_level = LOG_FATAL;
+ break;
+ default:
+ log_level = 0;
+ }
+ write_log("iohandler", log_level, line, strlen(line));
+}
+
+void init_log() {
+ load_log_targets();
+ bind_reload(reload_log_targets, 0);
+ iolog_backend = log_iohandler_backend;
+ printf_log("log", LOG_INFO, "initialized log system.");
+}
--- /dev/null
+/* log.h - NeonServ v5.6
+ * Copyright (C) 2011-2012 Philipp Kreil (pk910)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+#ifndef _log_h
+#define _log_h
+#include "main.h"
+
+#define LOG_INFO 0x01
+#define LOG_DEBUG 0x02
+#define LOG_IRCRAW 0x04
+#define LOG_MYSQL 0x08
+#define LOG_OVERRIDE 0x10
+#define LOG_WARNING 0x20
+#define LOG_ERROR 0x40
+#define LOG_FATAL 0x80
+
+#define LOG_ALL 0xff
+#define LOG_SECTIONS 8
+
+#ifndef DND_FUNCTIONS
+
+void printf_log(const char *module, const int section, const char *text, ...);
+void init_log();
+
+#endif
+#endif
#define DEFAULT_PID_FILE "neonserv.pid"
#define DEFAULT_CONF_FILE "neonserv.conf"
-#define DEFAULT_LOG_FILE "neonserv.log"
#include "main.h"
#include "signal.h"
#include "ModuleFunctions.h"
#include "IOHandler.h"
#include "statistics.h"
+#include "log.h"
struct ProcessState process_state;
-static FILE *log_fptr = NULL;
-
#ifdef HAVE_THREADS
pthread_mutex_t cache_sync;
pthread_mutex_t whohandler_sync, whohandler_mass_sync;
fprintf(stderr, "Unable to fork: %s\n", strerror(errno));
} else if (pid > 0) {
printf("Forking into the background (pid: %d)...\n", pid);
- putlog(LOGLEVEL_INFO, "Forking into the background (pid: %d)...\n", pid);
+ printf_log("main", LOG_INFO, "Forking into the background (pid: %d)...\n", pid);
exit(0);
}
setsid();
FILE *pidfile = fopen(process_state.pidfile, "w");
if (pidfile == NULL) {
fprintf(stderr, "Unable to create PID file: %s\n", strerror(errno));
- putlog(LOGLEVEL_ERROR, "Unable to create PID file: %s\n", strerror(errno));
+ printf_log("main", LOG_ERROR, "Unable to create PID file: %s\n", strerror(errno));
} else {
fprintf(pidfile, "%i\n", (int)getpid());
fclose(pidfile);
}
static int reload_configuration() {
- if(!loadConfig(process_state.config))
+ printf_log("main", LOG_DEBUG, "reloading configuration file: %s", process_state.config);
+ if(!loadConfig(process_state.config)) {
+ printf_log("main", LOG_ERROR, "could not reload configuration file: %s", process_state.config);
return 1;
+ }
if(process_state.loaded_config) {
if(!reload_mysql())
return 2;
/* INITIALISATION OF SUBSYSTEMS */
void initialize_subsystems() {
init_bind();
+ init_log();
+ printf_log("main", LOG_INFO, "starting up NeonServ %s subsystems...", NEONSERV_VERSION);
init_lang();
init_parser();
init_UserNode();
init_ChanNode();
init_ModeNode();
- init_bind();
init_modcmd();
register_module_commands();
init_handleinfohandler();
}
void shutdown_subsystems() {
+ printf_log("main", LOG_INFO, "stopping NeonServ subsystems...");
free_sockets(1);
//wait 50ms (run iohandler)
{
timeq_add(next_call, 0, main_checkauths, NULL);
}
-/* LOG BACKEND */
-
-void write_log(int loglevel, const char *line, int len) {
- SYNCHRONIZE(log_sync);
- if(!process_state.daemonized && (process_state.loglevel & loglevel)) {
- printf("%s", line);
- } else if(!process_state.daemonized && loglevel == LOGLEVEL_ERROR) {
- fprintf(stderr, "%s", line);
- }
- if(get_int_field("log.loglevel") & loglevel) {
- if(!log_fptr) {
- log_fptr = fopen(DEFAULT_LOG_FILE, "a");
- if(!log_fptr) goto write_log_end;
- }
- time_t rawtime;
- struct tm *timeinfo;
- time(&rawtime);
- timeinfo = localtime(&rawtime);
- char timestr[20];
- int timepos = strftime(timestr, 20, "%x %X ", timeinfo);
- fwrite(timestr, 1, timepos, log_fptr);
- fwrite(line, 1, len, log_fptr);
- }
- write_log_end:
- DESYNCHRONIZE(log_sync);
-}
-
-void putlog(int loglevel, const char *text, ...) {
- va_list arg_list;
- char logBuf[MAXLOGLEN];
- int pos;
- logBuf[0] = '\0';
- va_start(arg_list, text);
- pos = vsnprintf(logBuf, MAXLOGLEN - 1, text, arg_list);
- va_end(arg_list);
- if (pos < 0 || pos > (MAXLOGLEN - 1)) pos = MAXLOGLEN - 1;
- logBuf[pos] = '\0';
- write_log(loglevel, logBuf, pos);
-}
-
/* INSTALLATION SCRIPT */
static void check_firstrun() {
/* MODULAR ACCESSIBLE */ void restart_bot(int crash);
/* MODULAR ACCESSIBLE */ void stop_bot();
/* MODULAR ACCESSIBLE */ void reload_config();
-
-/* MODULAR ACCESSIBLE */ void putlog(int loglevel, const char *text, ...) PRINTF_LIKE(2, 3);
#endif
#endif
\ No newline at end of file
#include "DBHelper.h"
#include "EventLogger.h"
#include "tools.h"
+#include "log.h"
struct trigger_callback {
int botid;
triggerStr[0] = '\0';
trigger = malloc(sizeof(*trigger));
if (!trigger) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return 0;
}
trigger->botid = botid;
struct command_check_user_cache *data = malloc(sizeof(*data));
char **temp_argv = malloc(argc*sizeof(*temp_argv));
if (!data || !temp_argv) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
break;
}
memcpy(temp_argv, argv, argc*sizeof(*temp_argv));
}
cmdfunc = malloc(sizeof(*cmdfunc));
if (!cmdfunc) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return 0;
}
cmdfunc->botid = botid;
if(!cb) {
cb = malloc(sizeof(*cb));
if (!cb) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return 0;
}
cb->botid = botid;
}
cbind = malloc(sizeof(*cbind));
if (!cbind) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return 0;
}
cbind->botid = botid;
}
cbind = malloc(sizeof(*cbind));
if (!cbind) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return 0;
}
cbind->botid = botid;
}
botalias = malloc(sizeof(*botalias));
if (!botalias) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
botalias->botid = botid;
/* 000-001 */ #include "main.h"
/* 002-004 */ #include "tools.h"
/* 005-006 */ /* deprecated */
-/* 007-011 */ /* main.h */
+/* 007-009 */ /* main.h */
+/* 010 */ #include "log.h"
+/* 011 */ /* main.h */
/* 012 */ #include "BanNode.h"
/* 013-019 */ #include "bots.h"
/* 020-025 */ #include "ChanNode.h"
/* 007 */ (Function) restart_bot,
/* 008 */ (Function) stop_bot,
/* 009 */ (Function) reload_config,
-/* 010 */ (Function) putlog,
+/* 010 */ (Function) printf_log,
#ifdef HAVE_THREADS
/* 011 */ (Function) getCurrentThreadID,
#else
module = dlopen(fname, RTLD_LAZY);
}
if(!module) {
- putlog(LOGLEVEL_ERROR, "Error loading module '%s': %s not found.\n", name, fname);
+ printf_log("main", LOG_ERROR, "Error loading module '%s': %s not found.\n", name, fname);
return NULL;
}
void* initfunc = dlsym(module, "init_module");
sprintf(fname, "%s.dll", name);
HMODULE module = LoadLibrary(fname);
if(!module) {
- putlog(LOGLEVEL_ERROR, "Error loading module '%s': %s not found.\n", name, fname);
+ printf_log("main", LOG_ERROR, "Error loading module '%s': %s not found.\n", name, fname);
return NULL;
}
FARPROC initfunc = GetProcAddress(module, "init_module");
FARPROC modversion = GetProcAddress(module, "modversion");
#endif
if(!startfunc || !stopfunc || !modversion) {
- putlog(LOGLEVEL_ERROR, "Error loading module '%s': required symbols not found.\n", name);
+ printf_log("main", LOG_ERROR, "Error loading module '%s': required symbols not found.\n", name);
return NULL;
}
int version = ((int (*)(void)) modversion)();
if(version != MODULE_VERSION) {
- putlog(LOGLEVEL_ERROR, "Error loading module '%s': version mismatch ('%d' main code, '%d' module)\n", name, MODULE_VERSION, version);
+ printf_log("main", LOG_ERROR, "Error loading module '%s': version mismatch ('%d' main code, '%d' module)\n", name, MODULE_VERSION, version);
return NULL;
}
//start module
int errid;
int module_id = module_id_counter++;
if((errid = ((int (*)(void **, int)) initfunc)(global_functions, module_id))) {
- putlog(LOGLEVEL_ERROR, "Error loading module '%s': module reported error (errid: %d)\n", name, errid);
+ printf_log("main", LOG_ERROR, "Error loading module '%s': module reported error (errid: %d)\n", name, errid);
return NULL;
}
modinfo = malloc(sizeof(*modinfo));
if(!(user->flags & USERFLAG_ISAUTHED)) {
struct neonkick_event_join_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonkick", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
if(!(user->flags & USERFLAG_ISAUTHED)) {
struct neonserv_cmd_access_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
} else {
struct neonserv_cmd_access_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
CMD_BIND(neonserv_cmd_addban) {
struct neonserv_cmd_addban_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
}
struct neonserv_cmd_addtimeban_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
//but first lookup the auth to check if it really exists
struct neonserv_cmd_adduser_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
} else {
struct neonserv_cmd_adduser_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
//but first lookup the auth to check if it really exists
struct neonserv_cmd_assignrank_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
} else {
struct neonserv_cmd_assignrank_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
CMD_BIND(neonserv_cmd_ban) {
struct neonserv_cmd_ban_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
}
struct neonserv_cmd_chanservsync_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
//lookup auth
struct neonserv_cmd_chanservsync_auth_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = neonserv_cmd_chanservsync_used->client;
} else {
struct neonserv_cmd_clvl_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
CMD_BIND(neonserv_cmd_dehalfop) {
struct neonserv_cmd_dehalfop_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
CMD_BIND(neonserv_cmd_dehalfopall) {
struct neonserv_cmd_dehalfopall_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
} else {
struct neonserv_cmd_deluser_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
CMD_BIND(neonserv_cmd_deop) {
struct neonserv_cmd_deop_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
CMD_BIND(neonserv_cmd_deopall) {
struct neonserv_cmd_deopall_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
} else {
struct neonserv_cmd_giveowner_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
CMD_BIND(neonserv_cmd_halfop) {
struct neonserv_cmd_halfop_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
CMD_BIND(neonserv_cmd_halfopall) {
struct neonserv_cmd_halfopall_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
} else {
struct neonserv_cmd_invite_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
static struct neonserv_cmd_invite_timeout* neonserv_cmd_invite_add_timeout(char *nick, char *chan) {
struct neonserv_cmd_invite_timeout *entry = malloc(sizeof(*entry));
if (!entry) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return NULL;
}
entry->next = NULL;
CMD_BIND(neonserv_cmd_kick) {
struct neonserv_cmd_kick_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
CMD_BIND(neonserv_cmd_kickban) {
struct neonserv_cmd_kickban_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
CMD_BIND(neonserv_cmd_mode) {
struct neonserv_cmd_mode_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
if(!(user->flags & USERFLAG_ISAUTHED)) {
struct neonserv_cmd_myaccess_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
} else {
struct neonserv_cmd_myaccess_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
}
struct neonserv_cmd_nicklist_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
//but first lookup the auth to check if it really exists
struct neonserv_cmd_noregister_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
} else {
struct neonserv_cmd_noregister_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
CMD_BIND(neonserv_cmd_op) {
struct neonserv_cmd_op_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
}
struct neonserv_cmd_opall_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
CMD_BIND(neonserv_cmd_peek) {
struct neonserv_cmd_peek_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
CMD_BIND(neonserv_cmd_rename) {
struct neonserv_cmd_rename_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
}
struct neonserv_cmd_resync_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
} else {
struct neonserv_cmd_suspend_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
//ok parse the criterias
struct neonserv_cmd_trace_criteria *criteria = malloc(sizeof(*criteria));
if (!criteria) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
memset(criteria, 0, sizeof(*criteria));
}
struct neonserv_cmd_trim_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
nextmask = merge_argv_char(argv, 0, argc, ',');
struct neonserv_cmd_unban_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
} else {
struct neonserv_cmd_unsuspend_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
struct ChanNode *channel;
struct neonserv_cmd_unvisited_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
if(isModeSet(chan->modes, 'd') || isModeSet(chan->modes, 'D')) {
struct neonserv_cmd_up_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
}
struct neonserv_cmd_users_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
CMD_BIND(neonserv_cmd_voice) {
struct neonserv_cmd_voice_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
CMD_BIND(neonserv_cmd_voiceall) {
struct neonserv_cmd_voiceall_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
} else {
struct neonserv_cmd_wipeinfo_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
if(!(user->flags & USERFLAG_ISAUTHED)) {
struct neonserv_event_ctcp_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
if(!(user->flags & USERFLAG_ISAUTHED)) {
struct neonserv_event_join_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
if(!(chan->flags & CHANFLAG_CHAN_REGISTERED)) return;
struct neonserv_event_kick_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
if(argc)
temp_argv = malloc(argc*sizeof(*temp_argv));
if (!cache || (argc && !temp_argv)) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
if(argc) {
if(!(user->flags & USERFLAG_ISAUTHED)) {
struct neonserv_event_notice_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
if(!(user->flags & USERFLAG_ISAUTHED)) {
struct neonserv_event_topic_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
if(chan->spam_settings) return 0;
struct NeonSpamSettings *settings = malloc(sizeof(*settings));
if(!settings) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return 0;
}
MYSQL_RES *res;
return result;
joinnode = malloc(sizeof(*joinnode));
if(!joinnode) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return NULL;
}
joinnode->ident = strdup(chanuser->user->ident);
static void createSpamNode(struct ChanUser *chanuser) {
struct NeonSpamNode *spamnode = malloc(sizeof(*spamnode));
if(!spamnode) {
- perror("malloc() failed");
+ printf_log("neonserv", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
spamnode->lastmsg = 0;
} else {
struct neonspam_event_chanmsg_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonspam", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
} else {
struct neonspam_event_join_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("neonspam", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
struct global_cmd_extscript_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("global", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
//but first lookup the auth to check if it really exists
struct global_cmd_register_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("global", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
} else {
struct global_cmd_register_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("global", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
//but first lookup the auth to check if it really exists
struct global_cmd_setaccess_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("global", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
} else {
struct global_cmd_setaccess_cache *cache = malloc(sizeof(*cache));
if (!cache) {
- perror("malloc() failed");
+ printf_log("global", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return;
}
cache->client = client;
#include "../overall.h"
#include "../version.h"
#include "../mysqlConn.h"
+#include "../log.h"
extern void **global;
extern int module_id;
/* 007 */ #define restart_bot ((void (*)(int))global[7])
/* 008 */ #define stop_bot ((void (*)(void))global[8])
/* 009 */ #define reload_config ((void (*)(void))global[9])
-/* 010 */ #define putlog ((void (*)(int, const char *, ...))global[10])
+/* 010 */ #define printf_log ((void (*)(char *, int, const char *, ...))global[10])
#ifdef HAVE_THREADS
/* 011 */ #define getCurrentThreadID ((int (*)(void))global[11])
#endif
#include "mysqlConn.h"
#include "ConfigParser.h"
#include "tools.h"
+#include "log.h"
#define DATABASE_VERSION "20"
static void show_mysql_error();
}
}
fclose(f);
- }
+ } else
+ printf_log("main", LOG_ERROR | LOG_MYSQL, "File not found: database.sql");
f = fopen("database.defaults.sql", "r");
if (f) {
char line[4096];
}
}
fclose(f);
- }
+ } else
+ printf_log("main", LOG_ERROR | LOG_MYSQL, "File not found: database.defaults.sql");
do {
MYSQL_RES *res = mysql_store_result(mysql_conn);
mysql_free_result(res);
}
fclose(f);
} else
- perror("database.sql missing!");
+ printf_log("main", LOG_ERROR | LOG_MYSQL, "File not found: database.upgrade.sql");
do {
MYSQL_RES *res = mysql_store_result(mysql_conn);
mysql_free_result(res);
static void show_mysql_error() {
MYSQL *mysql_conn = get_mysql_conn();
//show mysql_error()
- putlog(LOGLEVEL_ERROR, "MySQL Error: %s\n", mysql_error(mysql_conn));
+ printf_log("main", LOG_ERROR | LOG_MYSQL, "Error: %s\n", mysql_error(mysql_conn));
}
void printf_mysql_query(const char *text, ...) {
va_end(arg_list);
if (pos < 0 || pos > (MYSQLMAXLEN - 2)) pos = MYSQLMAXLEN - 2;
queryBuf[pos] = '\0';
- putlog(LOGLEVEL_MYSQL, "MySQL: %s\n", queryBuf);
+ printf_log("main", LOG_MYSQL, "%s\n", queryBuf);
if(mysql_query(mysql_conn, queryBuf)) {
check_mysql();
if(mysql_query(mysql_conn, queryBuf)) {
va_end(arg_list);
if (pos < 0 || pos > (len - 2)) pos = len - 2;
queryBuf[pos] = '\0';
- putlog(LOGLEVEL_MYSQL, "MySQL: %s\n", queryBuf);
+ printf_log("main", LOG_MYSQL, "%s\n", queryBuf);
if(mysql_query(mysql_conn, queryBuf)) {
check_mysql();
if(mysql_query(mysql_conn, queryBuf)) {
#define timeval_is_bigger(x,y) ((x.tv_sec > y.tv_sec) || (x.tv_sec == y.tv_sec && x.tv_usec > y.tv_usec))
-#define perror(errmsg) (putlog(LOGLEVEL_ERROR, "ERROR (%s:%d) %s", __FILE__, __LINE__, errmsg))
-
#define MODSTATE_RELOAD 0x01
#define MODSTATE_STARTSTOP 0x02
#define MODSTATE_REBIND 0x03
#include "ClientSocket.h"
#include "IOHandler.h"
#include "ConfigParser.h"
+#include "log.h"
static void sigcrash();
static void sigexit();
void sighandler(int signum) {
- putlog(LOGLEVEL_INFO, "Received Signal %d\n", signum);
+ printf_log("main", LOG_INFO, "Received Signal %d\n", signum);
signal(signum, SIG_DFL);
switch(signum) {
case SIGABRT:
signame = "SIGUNKNOWN";
break;
}
- putlog(LOGLEVEL_ERROR, "NeonServ process crashed (%s)\n", signame);
+ printf_log("main", LOG_ERROR, "NeonServ process crashed (%s)\n", signame);
#ifndef WIN32
char gcore[50];
sprintf(gcore, "gcore %u", getpid());
int sysretn = system(gcore); //generate core file
sprintf(coregen, "core file generated. (%d)", sysretn);
- putlog(LOGLEVEL_ERROR | LOGLEVEL_INFO, "generated core file.\n");
+ printf_log("main", LOG_ERROR | LOG_INFO, "generated core file.\n");
#endif
- char *alertchan = get_string_field("General.alertchan");
- if(alertchan) {
- struct ChanNode *channel = getChanByName(alertchan);
- struct ClientSocket *client;
- if(channel && (client = getChannelBot(channel, 0))) {
- putsock(client, "PRIVMSG %s :\00304NeonServ received signal %d (%s). %s", alertchan, signum, signame, coregen);
- }
- }
//close all bots
struct ClientSocket *bot;
for(bot = getBots(SOCKET_FLAG_READY, NULL); bot; bot = getBots(SOCKET_FLAG_READY, bot)) {
bot->iofd = NULL;
}
}
- putlog(LOGLEVEL_INFO, "hard shutdown...\n");
+ printf_log("main", LOG_INFO, "hard shutdown...\n");
usleep(2000000);
//hard restart
restart_bot(1);
#include "timeq.h"
#include "IOHandler.h"
#include "tools.h"
+#include "log.h"
static struct timeq_entry *timeq_events;
#ifdef HAVE_THREADS
struct timeq_entry *entry = malloc(sizeof(*entry));
if (!entry)
{
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return NULL;
}
#ifdef HAVE_THREADS
#include "lang.h"
#include "ClientSocket.h"
#include "IPNode.h"
+#include "log.h"
static const struct default_language_entry msgtab[] = {
{"TIME_MASK_2_ITEMS", "%s and %s"}, /* {ARGS: "2 days", "1 hour"} */
struct ModeBuffer* initModeBuffer(struct ClientSocket *client, struct ChanNode *chan) {
struct ModeBuffer *modeBuf = malloc(sizeof(*modeBuf));
if(!modeBuf) {
- perror("malloc() failed");
+ printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
return NULL;
}
modeBuf->client = client;