added new multi log system
authorpk910 <philipp@zoelle1.de>
Thu, 27 Sep 2012 21:44:02 +0000 (23:44 +0200)
committerpk910 <philipp@zoelle1.de>
Thu, 27 Sep 2012 22:39:04 +0000 (00:39 +0200)
80 files changed:
Makefile.am
neonserv.example.conf
src/ChanNode.c
src/ChanUser.c
src/ClientSocket.c
src/DBHelper.c
src/EventLogger.c
src/HandleInfoHandler.c
src/IRCEvents.c
src/IRCParser.c
src/IRCQueue.c
src/ModeNode.c
src/UserNode.c
src/WHOHandler.c
src/bots.c
src/lang.c
src/log.c [new file with mode: 0644]
src/log.h [new file with mode: 0644]
src/main.c
src/main.h
src/modcmd.c
src/modules.c
src/modules/NeonKick.mod/event_neonkick_join.c
src/modules/NeonServ.mod/cmd_neonserv_access.c
src/modules/NeonServ.mod/cmd_neonserv_addban.c
src/modules/NeonServ.mod/cmd_neonserv_addtimeban.c
src/modules/NeonServ.mod/cmd_neonserv_adduser.c
src/modules/NeonServ.mod/cmd_neonserv_assignrank.c
src/modules/NeonServ.mod/cmd_neonserv_ban.c
src/modules/NeonServ.mod/cmd_neonserv_chanservsync.c
src/modules/NeonServ.mod/cmd_neonserv_clvl.c
src/modules/NeonServ.mod/cmd_neonserv_dehalfop.c
src/modules/NeonServ.mod/cmd_neonserv_dehalfopall.c
src/modules/NeonServ.mod/cmd_neonserv_deluser.c
src/modules/NeonServ.mod/cmd_neonserv_deop.c
src/modules/NeonServ.mod/cmd_neonserv_deopall.c
src/modules/NeonServ.mod/cmd_neonserv_giveowner.c
src/modules/NeonServ.mod/cmd_neonserv_halfop.c
src/modules/NeonServ.mod/cmd_neonserv_halfopall.c
src/modules/NeonServ.mod/cmd_neonserv_invite.c
src/modules/NeonServ.mod/cmd_neonserv_kick.c
src/modules/NeonServ.mod/cmd_neonserv_kickban.c
src/modules/NeonServ.mod/cmd_neonserv_mode.c
src/modules/NeonServ.mod/cmd_neonserv_myaccess.c
src/modules/NeonServ.mod/cmd_neonserv_nicklist.c
src/modules/NeonServ.mod/cmd_neonserv_noregister.c
src/modules/NeonServ.mod/cmd_neonserv_op.c
src/modules/NeonServ.mod/cmd_neonserv_opall.c
src/modules/NeonServ.mod/cmd_neonserv_peek.c
src/modules/NeonServ.mod/cmd_neonserv_rename.c
src/modules/NeonServ.mod/cmd_neonserv_resync.c
src/modules/NeonServ.mod/cmd_neonserv_suspend.c
src/modules/NeonServ.mod/cmd_neonserv_trace.c
src/modules/NeonServ.mod/cmd_neonserv_trim.c
src/modules/NeonServ.mod/cmd_neonserv_unban.c
src/modules/NeonServ.mod/cmd_neonserv_unsuspend.c
src/modules/NeonServ.mod/cmd_neonserv_unvisited.c
src/modules/NeonServ.mod/cmd_neonserv_up.c
src/modules/NeonServ.mod/cmd_neonserv_users.c
src/modules/NeonServ.mod/cmd_neonserv_voice.c
src/modules/NeonServ.mod/cmd_neonserv_voiceall.c
src/modules/NeonServ.mod/cmd_neonserv_wipeinfo.c
src/modules/NeonServ.mod/event_neonserv_ctcp.c
src/modules/NeonServ.mod/event_neonserv_join.c
src/modules/NeonServ.mod/event_neonserv_kick.c
src/modules/NeonServ.mod/event_neonserv_mode.c
src/modules/NeonServ.mod/event_neonserv_notice.c
src/modules/NeonServ.mod/event_neonserv_topic.c
src/modules/NeonSpam.mod/bot_NeonSpam.c
src/modules/NeonSpam.mod/event_neonspam_chanmsg.c
src/modules/NeonSpam.mod/event_neonspam_join.c
src/modules/global.mod/cmd_global_extscript.c
src/modules/global.mod/cmd_global_register.c
src/modules/global.mod/cmd_global_setaccess.c
src/modules/module.h
src/mysqlConn.c
src/overall.h
src/signal.c
src/timeq.c
src/tools.c

index fdfb7f1304091e8e1464c837d349f553b0752983..e0105d6d5997131236477125d25ac3194c05d0de 100644 (file)
@@ -212,6 +212,7 @@ neonserv_SOURCES = src/version.c \
       src/module_commands.c \
       src/ModuleFunctions.c \
       src/statistics.c \
+      src/log.c \
       src/memoryDebug.c
 
 neonserv_LDADD = $(MYSQL_LIBS) $(SYSTEM_LIBS)
index afa81c01de00b796ca245b5fcb01319709f51833..ded933c179bd62a859320beb944ef718f3ef1901 100644 (file)
     "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" {
index 41bbd455fd9d0df9783eb13860434ab700f86175..44a335f1cb822f2d7c414ebeef955781c93601c1 100644 (file)
@@ -22,6 +22,7 @@
 #include "ModeNode.h"
 #include "IRCEvents.h"
 #include "tools.h"
+#include "log.h"
 
 static struct ChanNode **chanList;
 
@@ -131,7 +132,7 @@ struct ChanNode* addChannel(const char *name) {
     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);
index 04fc29fc9f3a3880fd745177e9f2edd790a13f60..e18ce4dd57590d7a718f13cebfda8edfadd02243 100644 (file)
 #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;
@@ -53,7 +54,7 @@ struct ChanUser* addInvisibleChanUser(struct ChanNode *chan, struct UserNode *us
     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;
index eb11d88fc131558ff1bb698f883c37bd91144188..d8faf26d4a0ec7c56ae3475f083b300300517df3 100644 (file)
@@ -25,6 +25,7 @@
 #include "version.h"
 #include "IOHandler.h"
 #include "IRCEvents.h"
+#include "log.h"
 
 struct socket_list {
     struct ClientSocket *data;
@@ -54,7 +55,7 @@ void init_sockets() {
     sockets = malloc(sizeof(*sockets));
     if (!sockets)
     {
-        perror("malloc() failed");
+        printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
         return;
     }
     sockets->data = NULL;
@@ -156,9 +157,9 @@ int write_socket_force(struct ClientSocket *client, char* msg, int len) {
     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;
index 69bdf44fdd79b1e3f8de6fbccfd9e571a40656c9..6e2f84385c99a44abcd9b7f5c32b754ea66832ee 100644 (file)
@@ -27,6 +27,7 @@
 #include "ClientSocket.h"
 #include "bots.h"
 #include "ConfigParser.h"
+#include "log.h"
 
 void _loadUserSettings(struct UserNode *user) {
     SYNCHRONIZE(cache_sync);
@@ -298,7 +299,7 @@ static void event_user_registered(struct UserNode *user, char *new_mask) {
     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;
index 77956d799254e639c21a29fc3b8233d4e7713960..f5a8a315942489eb53c0be990d28fc29fbdd8497 100644 (file)
@@ -21,6 +21,7 @@
 #include "UserNode.h"
 #include "ChanNode.h"
 #include "DBHelper.h"
+#include "log.h"
 
 static struct Event *first_event = NULL, *last_event = NULL;
 
@@ -28,7 +29,7 @@ struct Event *createEvent(struct ClientSocket *client, struct UserNode *user, st
     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;
index edbf95b4aae6cbc7ec2cdaa58409345e86ff2cc9..8a8a46ce3a0ce205b422c01907c28f62c9e78835 100644 (file)
@@ -22,6 +22,7 @@
 #include "IRCEvents.h"
 #include "tools.h"
 #include "modules.h"
+#include "log.h"
 
 #define AUTHSERV_NICK "AuthServ"
 
@@ -40,7 +41,7 @@ static struct HandleInfoQueueEntry* addHandleInfoQueueEntry(struct ClientSocket
     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);
index 972850249a9f2d71970bbe70922d553c9936b6c6..2eea34d8ecc1067bddf693e2a721b6a748abeee7 100644 (file)
@@ -21,6 +21,7 @@
 #include "ChanUser.h"
 #include "ClientSocket.h"
 #include "mysqlConn.h"
+#include "log.h"
 
 struct binding {
     void *func;
@@ -105,7 +106,7 @@ int bind_##NAME(FUNCTYPE *func, int module_id) { \
     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; \
index bcb9f026897a838cc34cc392d903b4bba8820a2a..d9a707f63d024576c02c2a5bdc1cef516ed1515e 100644 (file)
@@ -31,6 +31,7 @@
 #include "timeq.h"
 #include "ConfigParser.h"
 #include "statistics.h"
+#include "log.h"
 
 struct irc_cmd *irc_commands = NULL;
 //static struct UserNode *registering_users = NULL;
@@ -59,9 +60,9 @@ void parse_line(struct ClientSocket *client, char *line) {
     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++;
@@ -91,7 +92,7 @@ static void register_irc_function(char *command, irc_cmd_t *func) {
     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;
@@ -112,7 +113,7 @@ static void parse_raw(struct ClientSocket *client, char *from, char *cmd, char *
     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);
     }
 }
 
@@ -384,8 +385,8 @@ static IRC_CMD(raw_join) {
         }
         
         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
@@ -897,7 +898,7 @@ static void raw_005_network(struct ClientSocket *client, char *value) {
         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;
         }
     }
index 296850d076d102cf885bc8a338e9f7ef693882ba..a7cc1a4d00fd52521ba0cc108a3db83c9dbf0d69 100644 (file)
@@ -18,6 +18,7 @@
 #include "ClientSocket.h"
 #include "IOHandler.h"
 #include "tools.h"
+#include "log.h"
 
 #define MAXPENALTY 8 /* 4 messages */
 
@@ -41,7 +42,7 @@ static IOHANDLER_CALLBACK(queue_callback);
 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;
@@ -131,7 +132,7 @@ int queue_add(struct ClientSocket *client, char* msg, int len) {
     } 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);
index 8cc5b67a07328f6f055060bc2f5105f5b009a9db..f3579cd42b71654ae34d168eddec03bf6393b5c8 100644 (file)
@@ -19,6 +19,7 @@
 #include "ChanUser.h"
 #include "UserNode.h"
 #include "BanNode.h"
+#include "log.h"
 
 static int modes_with_strarg, modes_with_intarg, modes_count;
 
@@ -77,7 +78,7 @@ struct ModeNode *createModeNode(struct ChanNode *chan) {
     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;
index a82e5ec701685f538abb8cedb7b79383c0f75f7f..cd8735e8f5ba7716b4cb5c3996d04b1353d53c7f 100644 (file)
@@ -20,6 +20,7 @@
 #include "tools.h"
 #include "IRCEvents.h"
 #include "IPNode.h"
+#include "log.h"
 
 static struct UserNode **userList;
 
@@ -288,7 +289,7 @@ struct UserNode* addUser(const char *nick) {
     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);
@@ -350,7 +351,7 @@ struct UserNode* createTempUser(const char *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;
@@ -398,7 +399,7 @@ struct UserNode* createTempUserMask(const char *mask) {
             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;
@@ -421,7 +422,7 @@ struct UserNode* createTempUserMask(const char *mask) {
             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);
@@ -448,7 +449,7 @@ struct UserNode* createTempUserMask(const char *mask) {
                 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);
index 3294e3802f3a244575dc0a1901795f379138f16e..5db3db6a3d58be68ad50a402308033f61d004c6c 100644 (file)
@@ -23,6 +23,7 @@
 #include "ClientSocket.h"
 #include "IPNode.h"
 #include "modules.h"
+#include "log.h"
 
 #define WHOQUEUETYPE_ISONQUEUE 0x01
 #define WHOQUEUETYPE_USERLIST  0x02
@@ -65,7 +66,7 @@ static struct WHOQueueEntry* addWHOQueueEntry(struct ClientSocket *client) {
     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;
     }
index 076c0cb12a8be738fe98509b521dcd6cd1095d39..7da678c97ffb3b4a185f9b0dea6b74f3c69431ae 100644 (file)
@@ -27,6 +27,7 @@
 #include "DBHelper.h"
 #include "IRCEvents.h"
 #include "tools.h"
+#include "log.h"
 
 struct cmd_bot_alias {
     int botid;
@@ -275,7 +276,7 @@ void set_bot_alias(int botid, char *alias) {
     }
     botalias = malloc(sizeof(*botalias));
     if (!botalias) {
-        perror("malloc() failed");
+        printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
         return;
     }
     botalias->botid = botid;
index 22b0c77c24c9f468855f7bd870b3f455016a6ba6..7d1532bf424bd7003cca2560c4da19ef26e1f0c2 100644 (file)
@@ -19,6 +19,7 @@
 #include "DBHelper.h"
 #include "mysqlConn.h"
 #include "tools.h"
+#include "log.h"
 
 #define DEFAULT_LANG_TAG "EN"
 #define DEFAULT_LANG_NAME "English"
@@ -54,7 +55,7 @@ static struct language* add_language(char *langtag, char *langname) {
     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);
@@ -143,7 +144,7 @@ void register_language_string(struct language *lang, char *ident, char *text) {
     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);
@@ -211,7 +212,7 @@ char *build_language_string(struct UserNode *user, char *buffer, const char *msg
     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;
         }
     }
diff --git a/src/log.c b/src/log.c
new file mode 100644 (file)
index 0000000..6e1ba87
--- /dev/null
+++ b/src/log.c
@@ -0,0 +1,291 @@
+/* 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.");
+}
diff --git a/src/log.h b/src/log.h
new file mode 100644 (file)
index 0000000..657e527
--- /dev/null
+++ b/src/log.h
@@ -0,0 +1,39 @@
+/* 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
index 23903d93cc26c9ddf4e8804af3887713bd1f244a..d2c482af117619ca01653c4aa38b113f3f628933 100644 (file)
@@ -17,7 +17,6 @@
 
 #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;
@@ -120,7 +118,7 @@ static void main_daemonize() {
         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();
@@ -129,7 +127,7 @@ static void main_daemonize() {
     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);
@@ -142,8 +140,11 @@ static void main_daemonize() {
 }
 
 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;
@@ -163,12 +164,13 @@ static int reload_configuration() {
 /* 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();
@@ -183,6 +185,7 @@ void initialize_subsystems() {
 }
 
 void shutdown_subsystems() {
+    printf_log("main", LOG_INFO, "stopping NeonServ subsystems...");
     free_sockets(1);
     //wait 50ms (run iohandler)
     {
@@ -485,46 +488,6 @@ static TIMEQ_CALLBACK(main_checkauths) {
     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() {
index 85e4fd8e48af5a8c07a4826bce37eb4aed2d6fe9..1f1d0f315aae47cdf820617762545a1af4f166f1 100644 (file)
@@ -52,7 +52,5 @@ extern pthread_mutex_t whohandler_sync, whohandler_mass_sync;
 /* 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
index 0c1e92e67571f7184904813271b7a6561d30857c..fd71523edfd64869f47cb60a0913c7f0bc762656 100644 (file)
@@ -28,6 +28,7 @@
 #include "DBHelper.h"
 #include "EventLogger.h"
 #include "tools.h"
+#include "log.h"
 
 struct trigger_callback {
     int botid;
@@ -113,7 +114,7 @@ static char* get_channel_trigger(int botid, int clientid, struct ChanNode *chan)
         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;
@@ -380,7 +381,7 @@ static void handle_command(struct ClientSocket *client, struct UserNode *user, s
                 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));
@@ -630,7 +631,7 @@ int register_command(int botid, char *name, int module_id, cmd_bind_t *func, int
     }
     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;
@@ -655,7 +656,7 @@ int set_trigger_callback(int botid, int module_id, trigger_callback_t *func) {
     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;
@@ -709,7 +710,7 @@ int bind_botwise_cmd_to_function(int botid, int clientid, char *cmd, struct cmd_
     }
     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;
@@ -755,7 +756,7 @@ int bind_botwise_cmd_to_command(int botid, int clientid, char *cmd, char *func)
     }
     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;
@@ -1009,7 +1010,7 @@ void register_command_alias(int botid, char *alias) {
     }
     botalias = malloc(sizeof(*botalias));
     if (!botalias) {
-        perror("malloc() failed");
+        printf_log("main", LOG_ERROR, "%s:%d malloc() failed", __FILE__, __LINE__);
         return;
     }
     botalias->botid = botid;
index 7310c88465152f21f1dc0351869489867d1346e4..325621e9da06820c4e47a371608cafa262b15bf4 100644 (file)
@@ -22,7 +22,9 @@
 /* 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"
@@ -67,7 +69,7 @@ void *global_functions[] = {
 /* 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
@@ -312,7 +314,7 @@ struct ModuleInfo *loadModule(char *name) {
         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");
@@ -323,7 +325,7 @@ struct ModuleInfo *loadModule(char *name) {
     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");
@@ -332,19 +334,19 @@ struct ModuleInfo *loadModule(char *name) {
     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));
index 40439ebbc707477c7f8436dd8c1f446e915f7aef..6dc1224988f2200eaaabd91cce47f579603e7841 100644 (file)
@@ -38,7 +38,7 @@ static void neonkick_event_join(struct ChanUser *chanuser) {
     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;
index b00046c6a640251e669e54ddc0014238c2dcfc7d..ce84cd4b5d29300afc1c5e7f99c185286c6718f3 100644 (file)
@@ -36,7 +36,7 @@ CMD_BIND(neonserv_cmd_access) {
         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;
@@ -67,7 +67,7 @@ CMD_BIND(neonserv_cmd_access) {
         } 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;
index 196e890fe6c9b37ac05bc5047fa681e17c76374f..63e82247ac0369979802039e5e9e824c81be557b 100644 (file)
@@ -35,7 +35,7 @@ struct neonserv_cmd_addban_cache {
 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;
index da4ff6a398c4b9c5d55826e318cdb6211b9ba196..2e096f9584dc86f56ba747ee44788e4103b9240e 100644 (file)
@@ -42,7 +42,7 @@ CMD_BIND(neonserv_cmd_addtimeban) {
     }
     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;
index 6a11fa1e9cbbfe657912fdf535d9d375071495fa..e8b14bd98619aebc836807bec3685b85ba2f5e2c 100644 (file)
@@ -64,7 +64,7 @@ CMD_BIND(neonserv_cmd_adduser) {
             //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;
@@ -91,7 +91,7 @@ CMD_BIND(neonserv_cmd_adduser) {
         } 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;
index 9b4962711c9becfbeee688dd9d424d67d356bf7b..19a906a3df20e89898ce279c4ddcf60588d5c21f 100644 (file)
@@ -59,7 +59,7 @@ CMD_BIND(neonserv_cmd_assignrank) {
             //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;
@@ -85,7 +85,7 @@ CMD_BIND(neonserv_cmd_assignrank) {
         } 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;
index be8244fc4e1be7627637a6f3408c19b0b7d7dd30..2a419eb6c94860305df271f62cbf1436393042cb 100644 (file)
@@ -33,7 +33,7 @@ struct neonserv_cmd_ban_cache {
 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;
index f918d272439edbaee0642ca7c7a9836aaef06590..e4e00966295da78816a2dee09f23912852491388 100644 (file)
@@ -95,7 +95,7 @@ CMD_BIND(neonserv_cmd_chanservsync) {
     }
     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;
@@ -214,7 +214,7 @@ static void neonserv_cmd_chanservsync_notice_listener(struct UserNode *user, str
             //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;
index eb99e42213b021cf016deea399ca2dc102f88d49..159d54048912152167a694178f50f0bbf743f00f 100644 (file)
@@ -67,7 +67,7 @@ CMD_BIND(neonserv_cmd_clvl) {
         } 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;
index 46d888f7e987f2ee746c601462a0cf5c175398aa..28821801233c98525db932cb0508e34c0f7dd15f 100644 (file)
@@ -34,7 +34,7 @@ struct neonserv_cmd_dehalfop_cache {
 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;
index 49a770d251396ee9614b8e9ae44398839183863a..ce948ac328c904198fa8fe458588ec6fb350c917 100644 (file)
@@ -34,7 +34,7 @@ struct neonserv_cmd_dehalfopall_cache {
 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;
index 3d2c17bff9e3a6ca56d5c8977412797fb58e8fee..e283f185db75db6373da5ab228beec8a60cc72f0 100644 (file)
@@ -51,7 +51,7 @@ CMD_BIND(neonserv_cmd_deluser) {
         } 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;
index cf2328e87d8affef8554b732df5c8171ad5a8d54..d030b8e0921425a044f41c5ad50fa433dce6a299 100644 (file)
@@ -34,7 +34,7 @@ struct neonserv_cmd_deop_cache {
 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;
index b81239b5c8137a540bb3ed8a1b0e809427e7b851..0299a8b1eb86ed02ad6b8cbddf99346896e4203b 100644 (file)
@@ -34,7 +34,7 @@ struct neonserv_cmd_deopall_cache {
 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;
index 1c7b65e42441e1993b1bc01604bb58d66862a927..67b146329916e4db0f8f52ccb722b0fc7d8a0caf 100644 (file)
@@ -66,7 +66,7 @@ CMD_BIND(neonserv_cmd_giveowner) {
         } 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;
index 2cdff8abd76e0b3dd4a7a8c5deb96ce428e3c505..8c8338981369e380def2a1b8d222264074d7e787 100644 (file)
@@ -33,7 +33,7 @@ struct neonserv_cmd_halfop_cache {
 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;
index d18bb68d397ec0c86fa44c4e6feb2fdfefc3429f..5ce22e86ddd58f374b0757e13fcf71ab7e65669b 100644 (file)
@@ -34,7 +34,7 @@ struct neonserv_cmd_halfopall_cache {
 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;
index 22184abda22fcb89fb24bcf8a790c490c8074016..b9bce2855b8c626af6fa90f9b8f72d95944ea595 100644 (file)
@@ -72,7 +72,7 @@ CMD_BIND(neonserv_cmd_invite) {
     } 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;
@@ -139,7 +139,7 @@ static TIMEQ_CALLBACK(neonserv_cmd_invite_timeout_timeout) {
 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;
index 005149ce34521c25be26f1b447cbf19106b9d42b..a4d3481e713e242d0b808c9451aad83c2acb6851 100644 (file)
@@ -35,7 +35,7 @@ struct neonserv_cmd_kick_cache {
 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;
index 1fda7d001da766a8ea91321058059d4dbee8f770..a580764bbc1480da9536fded466bd8ee1d1e6898 100644 (file)
@@ -35,7 +35,7 @@ struct neonserv_cmd_kickban_cache {
 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;
index 9aae43e9374209395f8d70e512c064148323652e..992ff4623b93e5ddd1da334b7bc2aeb49cd5bb25 100644 (file)
@@ -34,7 +34,7 @@ struct neonserv_cmd_mode_cache {
 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;
index d1204f4055ffb028db2d2c82fb4e9b146e4ad085..6fa063b2508736ce087f704068445dd6fe6d05f4 100644 (file)
@@ -40,7 +40,7 @@ CMD_BIND(neonserv_cmd_myaccess) {
         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;
@@ -78,7 +78,7 @@ CMD_BIND(neonserv_cmd_myaccess) {
         } 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;
index 12311600c968eae3553612bd75c5a7949349f524..0fad5a84b522ab4ebec2e70f346f60d375828243 100644 (file)
@@ -66,7 +66,7 @@ CMD_BIND(neonserv_cmd_nicklist) {
     }
     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;
index 3044df360292128a8c257d4e77c4a9423364a68f..2c15f49d7d2c7b8e74bb6707f449999968fdb4aa 100644 (file)
@@ -70,7 +70,7 @@ CMD_BIND(neonserv_cmd_noregister) {
             //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;
@@ -98,7 +98,7 @@ CMD_BIND(neonserv_cmd_noregister) {
         } 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;
index df987b2316642633b42228b4433532441895d02c..d6679bcff4142b581d53cf69de5d5dd9ab985aa6 100644 (file)
@@ -33,7 +33,7 @@ struct neonserv_cmd_op_cache {
 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;
index a18964f986751818bee76df7633c90a09b981fff..3f2646ac6082cb832237f4bc4515e3b793ff363e 100644 (file)
@@ -38,7 +38,7 @@ CMD_BIND(neonserv_cmd_opall) {
     }
     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;
index 91f88fa5ecfded4bece152b3870a5ee0c152a73f..fe600cd589b4c342ecae326ca7de7e20a4eb5dfc 100644 (file)
@@ -31,7 +31,7 @@ struct neonserv_cmd_peek_cache {
 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;
index d88b0002bd9dabf07706b17c0b976a13cff49f10..34b72b0dbd239c5de88659c817c44c9579b8a532 100644 (file)
@@ -35,7 +35,7 @@ static void neonserv_cmd_rename_async1(struct ClientSocket *client, struct Clien
 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;
index 7c5948e9a63f02a7c4f662f239dc2b75a74638de..46a095ee15afc6358b16039021dc28b4480937ff 100644 (file)
@@ -51,7 +51,7 @@ CMD_BIND(neonserv_cmd_resync) {
     }
     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;
index 2ef151f67e390e82597b08bdf5d3e0b9c461f375..e4fc1582ba05b29d170b5c5e4a4ffd91baeb7edc 100644 (file)
@@ -51,7 +51,7 @@ CMD_BIND(neonserv_cmd_suspend) {
         } 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;
index 2cceb927a94b3ddec471965f4d45b94839bee5d4..49dc741638a841ccb4efec9a6f267a2b7aef04a8 100644 (file)
@@ -38,7 +38,7 @@ CMD_BIND(neonserv_cmd_trace) {
     //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));
index a9e49dc69ea301b1fbec002fb7c4788da4f1900f..52478a99ff80c950aa72a1830c8011b1a9e9c392 100644 (file)
@@ -107,7 +107,7 @@ CMD_BIND(neonserv_cmd_trim) {
     }
     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;
index f145e330a06c24c22dcdce749c1ce9160f6e2f0c..6361bb82cfedf17bd8784f7b93d05bcac086d8af 100644 (file)
@@ -41,7 +41,7 @@ CMD_BIND(neonserv_cmd_unban) {
     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;
index f70c884dd313b99e3b641b71a983f15f819cda85..7c883034be9ce030270496cec7ff7ba2a0a0c216 100644 (file)
@@ -51,7 +51,7 @@ CMD_BIND(neonserv_cmd_unsuspend) {
         } 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;
index fc00afacc25c162b11d9af2397cb155c8b53fe22..5f1572e17ee823fc4075f1ce1f8359d064bf9768 100644 (file)
@@ -69,7 +69,7 @@ static void neonserv_check_unvisited(struct ClientSocket *client, struct ClientS
     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;
index 8a531f00d0e5f15399974a5b64cf01dd088d8185..a5d4d8527506a2249a147c4b86062110969cb7c9 100644 (file)
@@ -35,7 +35,7 @@ CMD_BIND(neonserv_cmd_up) {
     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;
index 54425261910e3e0aafd374fad482bf5b89b6c0c1..73aa173b20585199f2c7e8d973d5b04e95b2568a 100644 (file)
@@ -44,7 +44,7 @@ CMD_BIND(neonserv_cmd_users) {
     }
     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;
index e4639b904c6bc04ecc41223a58e0b17d1ae2be8d..ea3de407ed81492f0cdd920dc40dac26d63ff5f0 100644 (file)
@@ -33,7 +33,7 @@ struct neonserv_cmd_voice_cache {
 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;
index fd4bafb41c5c2f6d74094b58f3bdda2a40ba72f8..a1c2325e7103e853c5a0951a887fad7e9635f648 100644 (file)
@@ -33,7 +33,7 @@ struct neonserv_cmd_voiceall_cache {
 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;
index e09851e8a237b97847d1e1f563ca08f05470068c..bde1a249e6559deacd30914b85c4b8b77c6e08da 100644 (file)
@@ -51,7 +51,7 @@ CMD_BIND(neonserv_cmd_wipeinfo) {
         } 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;
index abb7d664098ac7ae2c1e03a8c32d86b9f4d0f304..200b80f584a2170c92c467416b62f00b6a652b54 100644 (file)
@@ -36,7 +36,7 @@ static void neonserv_event_chanctcp(struct UserNode *user, struct ChanNode *chan
     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;
index 8903959038ec3b33ab637577be51b76e1963efb3..5f77f4259d13db411edf02171f7581243916e61d 100644 (file)
@@ -53,7 +53,7 @@ static void neonserv_event_join(struct ChanUser *chanuser) {
     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;
index 1fc54090e7cdd20403bb43253e30d3abfa650ee9..2daf63aae33b504b6b8e704faec3d19147098d9e 100644 (file)
@@ -58,7 +58,7 @@ static void neonserv_event_kick(struct UserNode *user, struct ChanUser *target,
     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;
index 255c07927410dbd1293e64e8ac47a30d91df759b..79264931d1298b08d241547c8c360d2ac131bb0e 100644 (file)
@@ -38,7 +38,7 @@ static void neonserv_event_mode(struct UserNode *user, struct ChanNode *chan, ch
     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) {
index 408636ac5b11fcb1912f0a2f584d5701589dafd4..c15089a4ed3d6ce72a1a161c229202c8324239ad 100644 (file)
@@ -34,7 +34,7 @@ static void neonserv_event_channotice(struct UserNode *user, struct ChanNode *ch
     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;
index 9082989d840340d1a2eeabba39ec5e836bdb7453..3958f8308c69e71a39dd0eea09cdac7d02cbd975 100644 (file)
@@ -34,7 +34,7 @@ static void neonserv_event_topic(struct UserNode *user, struct ChanNode *chan, c
     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;
index d261b790dd13542319104af63f6c63922db43187..dd2e4d1043fc722ecdabd593808150fba2fda330 100644 (file)
@@ -225,7 +225,7 @@ int loadNeonSpamSettings(struct ChanNode *chan) {
     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;
@@ -321,7 +321,7 @@ static struct NeonSpamJoinNode *getNeonSpamJoinNode(struct ChanUser *chanuser) {
         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);
@@ -336,7 +336,7 @@ static struct NeonSpamJoinNode *getNeonSpamJoinNode(struct ChanUser *chanuser) {
 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;
index 648f505760570062385e557873cccc3beb879795..5e7f1aeeac1d305c01bb875b4f4f9bf43e87b617 100644 (file)
@@ -154,7 +154,7 @@ static void neonspam_event_chanmsg(struct UserNode *user, struct ChanNode *chan,
         } 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;
index 53280d4910aa8d8dfc83ce082108d2b464254dc5..f34b1a387f89917f41e3274393465cca047d33f8 100644 (file)
@@ -46,7 +46,7 @@ static void neonspam_event_join(struct ChanUser *chanuser) {
         } 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;
index 0d5e6563685037ab757ecb952fe568b9fceea045..74cde9d2f646c415cc11e226b71b72f671ade84f 100644 (file)
@@ -126,7 +126,7 @@ CMD_BIND(global_cmd_extscript) {
     
     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;
index 3e69c2674cb17d3e2e5a675e45a04672fd86728b..03fa9323f4294f3183a07e4707eea3ceacb7fe58 100644 (file)
@@ -96,7 +96,7 @@ CMD_BIND(global_cmd_register) {
             //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;
@@ -125,7 +125,7 @@ CMD_BIND(global_cmd_register) {
         } 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;
index f568ff0004e9d7e479b8ebacf9f100d7955b6948..8753cc30ac74442275e9b83c7a6daa4dfc057de0 100644 (file)
@@ -60,7 +60,7 @@ CMD_BIND(global_cmd_setaccess) {
             //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;
@@ -86,7 +86,7 @@ CMD_BIND(global_cmd_setaccess) {
         } 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;
index 25a767690264df5fd68ae73cd943169478f273d4..1b9dac7a55d75aa244c732b4ac012c004e57a235 100644 (file)
@@ -20,6 +20,7 @@
 #include "../overall.h"
 #include "../version.h"
 #include "../mysqlConn.h"
+#include "../log.h"
 
 extern void **global;
 extern int module_id;
@@ -35,7 +36,7 @@ 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
index 4673c7dbe7c8767014ee2d5586a4fb872cca91d6..45ab1931dee8766b7e13c9a4a15da6cfa41fd3fc 100644 (file)
@@ -18,6 +18,7 @@
 #include "mysqlConn.h"
 #include "ConfigParser.h"
 #include "tools.h"
+#include "log.h"
 #define DATABASE_VERSION "20"
 
 static void show_mysql_error();
@@ -160,7 +161,8 @@ void init_mysql() {
                 }
             }
             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];
@@ -175,7 +177,8 @@ void init_mysql() {
                 }
             }
             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); 
@@ -209,7 +212,7 @@ void init_mysql() {
             }
             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); 
@@ -232,7 +235,7 @@ void free_mysql() {
 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, ...) {
@@ -246,7 +249,7 @@ 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)) {
@@ -266,7 +269,7 @@ void printf_long_mysql_query(int len, const char *text, ...) {
     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)) {
index 26ff10ebe0d54466b92ea6f6a371ef40116c5488..d500e4771a47cd13d18d69c628ae49d16009da2a 100644 (file)
 
 #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
index bc444465089f1b2faa2f5d3ce03366c3ae3c041a..4e8f9a5d72f7a2a85ba77d186f549e5fd1e833a8 100644 (file)
 #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:
@@ -66,22 +67,14 @@ static void sigcrash(int signum) {
             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)) {
@@ -91,7 +84,7 @@ static void sigcrash(int signum) {
             bot->iofd = NULL;
         }
     }
-    putlog(LOGLEVEL_INFO, "hard shutdown...\n");
+    printf_log("main", LOG_INFO, "hard shutdown...\n");
     usleep(2000000);
     //hard restart
     restart_bot(1);
index c95068ddaf0ea128c4ff108f4ee07fc5a703c975..c18227a9d9b837aec76a18033a0e8a9579969170 100644 (file)
@@ -18,6 +18,7 @@
 #include "timeq.h"
 #include "IOHandler.h"
 #include "tools.h"
+#include "log.h"
 
 static struct timeq_entry *timeq_events;
 #ifdef HAVE_THREADS
@@ -47,7 +48,7 @@ struct timeq_entry* timeq_uadd(int useconds, int module_id, timeq_callback_t *ca
     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
index 5447232a347f391f5881ff7a4cdf6244aa24e000..0232671c5050767aca56177a5bf5a7731ce0449d 100644 (file)
@@ -20,6 +20,7 @@
 #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"} */
@@ -388,7 +389,7 @@ int getCurrentSecondsOfDay() {
 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;