# HG changeset patch # User Markus Bröker # Date 1229179223 -3600 # Node ID d3554afaa7687956846a00145e6b0f753191da79 # Parent 213c3d4abc6671d4fde3e088b36d9a6fc5aee842 mcbot-0.94-5 Changelog Compat.c added: * provides a safe strdup replacement * snprintf and fdopen may follow... garbage_collection improved Nasty compiler warning removed in parse.c committer: Markus Bröker diff --git a/debian/changelog b/debian/changelog --- a/debian/changelog +++ b/debian/changelog @@ -1,4 +1,4 @@ -mcbot (0.94-4) unstable; urgency=low +mcbot (0.94-5) unstable; urgency=low * Initial Release * the location of mcbot.cgi is stored in the db @@ -11,5 +11,6 @@ * irc_login connects now to the proper (non-freenode.net) server * privmsgs will be send to the proper location... * A simple garbage collector fills the memory leaks... + * compat.c added for XOPEN_SOURCE features - not finished yet -- Markus Broeker Sat, 10 Aug 2008 16:48:54 +0200 diff --git a/include/compat.h b/include/compat.h new file mode 100644 --- /dev/null +++ b/include/compat.h @@ -0,0 +1,11 @@ +/** + * $Id: irc.h 171 2008-08-10 18:00:10Z mbroeker $ + * $URL: http://localhost/svn/c/mcbot/trunk/include/compat.h $ + * + */ + +#ifndef COMPAT_H +#define COMPAT_H + +char *compat_strdup (const char *); +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,7 +16,7 @@ INCLUDE_DIRECTORIES(../include) # Target Definitions -ADD_EXECUTABLE(mcbot config.c database.c irc.c main.c parse.c) +ADD_EXECUTABLE(mcbot compat.c config.c database.c irc.c main.c parse.c) ADD_EXECUTABLE(dbtool database.c dbtool.c) # Install Rules diff --git a/src/compat.c b/src/compat.c new file mode 100644 --- /dev/null +++ b/src/compat.c @@ -0,0 +1,21 @@ +/** + * $Id: config.c 171 2008-08-10 18:20:39Z mbroeker $ + * $URL: http://localhost/svn/c/mcbot/trunk/src/compat.c $ + * + */ +#include +#include +#include + +#include + +char *compat_strdup (const char *s) +{ + char *buf; + + buf = malloc (strlen (s) + 1); + if (buf != NULL) + strcpy (buf, s); + + return buf; +} diff --git a/src/config.c b/src/config.c --- a/src/config.c +++ b/src/config.c @@ -8,6 +8,7 @@ #include #include +#include #include const @@ -57,7 +58,7 @@ while (CONFIG_OPTIONS[i] != NULL) { if (!strcmp (CONFIG_OPTIONS[i], token)) { if (value) - line[i] = strdup (value); + line[i] = compat_strdup (value); } i++; } @@ -72,15 +73,15 @@ if (line[i] != NULL) switch (i) { case 0: /* NICK */ - uc->nick = strdup (line[i]); + uc->nick = compat_strdup (line[i]); free (line[i]); break; case 1: /* PASSWORD */ - uc->pass = strdup (line[i]); + uc->pass = compat_strdup (line[i]); free (line[i]); break; case 2: /* SERVER */ - uc->server = strdup (line[i]); + uc->server = compat_strdup (line[i]); free (line[i]); break; case 3: /* PORT */ @@ -88,11 +89,11 @@ free (line[i]); break; case 4: /* CHANNEL */ - uc->channel = strdup (line[i]); + uc->channel = compat_strdup (line[i]); free (line[i]); break; case 5: /* TOPIC */ - uc->topic = strdup (line[i]); + uc->topic = compat_strdup (line[i]); free (line[i]); break; } diff --git a/src/irc.c b/src/irc.c --- a/src/irc.c +++ b/src/irc.c @@ -17,6 +17,7 @@ #include +#include #include #define VERSION_STRING "MCBOT on GNU/LINUX" @@ -147,10 +148,12 @@ char *token; char *ptr; - if (garbage_collector != NULL) + if (garbage_collector != NULL) { free (garbage_collector); + garbage_collector = NULL; + } - if ((theLine = strdup (line)) == NULL) + if ((theLine = compat_strdup (line)) == NULL) return "ENOMEM"; else garbage_collector = theLine; @@ -323,6 +326,7 @@ return command; case 401: /* NO SUCH NICK/CHANNEL */ case 403: /* THAT CHANNEL DOESN'T EXIST */ + case 412: /* NO TEXT TO SEND */ case 441: /* THEY AREN'T ON THIS CHANNEL */ return command; case 474: diff --git a/src/parse.c b/src/parse.c --- a/src/parse.c +++ b/src/parse.c @@ -244,9 +244,10 @@ case 18: /* tell */ if ((token = strtok (NULL, " "))) { if ((parameters = strtok (NULL, "\r\n"))) { - snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n", - ('*' == *token) ? ++token : message->channel, token, db_lookup (DATABASE_FILE, - parameters)); + if (*token == '*') + message->channel = ++token; + snprintf (msg, 512, "PRIVMSG %s :%s, %s\r\n", message->channel, token, + db_lookup (DATABASE_FILE, parameters)); } } return msg;