Module: ngircd.git Branch: master Commit: 3ab00e3a11acfd22741e58aa409bb2026e0665ba URL: http://ngircd.barton.de/cgi-bin/gitweb.cgi?p=ngircd.git&a=commit;h=3ab00...
Author: Federico G. Schwindt fgsch@lodoss.net Date: Sat Apr 20 00:19:03 2013 +0100
Change Lists_MakeMask() to receive a buffer for the mask
Change callers accordingly so they don't rely on a global buffer and rename Mask to Pattern where it makes sense since some functions where indeed receiving a pattern and not a mask.
---
src/ngircd/class.c | 14 ++++++++++---- src/ngircd/class.h | 4 ++-- src/ngircd/defines.h | 4 +++- src/ngircd/irc-mode.c | 8 ++++---- src/ngircd/lists.c | 46 ++++++++++++++++------------------------------ src/ngircd/lists.h | 2 +- 6 files changed, 36 insertions(+), 42 deletions(-)
diff --git a/src/ngircd/class.c b/src/ngircd/class.c index 800e993..156f943 100644 --- a/src/ngircd/class.c +++ b/src/ngircd/class.c @@ -98,24 +98,30 @@ Class_HandleServerBans(CLIENT *Client)
GLOBAL bool -Class_AddMask(const int Class, const char *Mask, time_t ValidUntil, +Class_AddMask(const int Class, const char *Pattern, time_t ValidUntil, const char *Reason) { + char mask[MASK_LEN]; + assert(Class < CLASS_COUNT); assert(Mask != NULL); assert(Reason != NULL);
- return Lists_Add(&My_Classes[Class], Lists_MakeMask(Mask), + Lists_MakeMask(Pattern, mask, sizeof(mask)); + return Lists_Add(&My_Classes[Class], mask, ValidUntil, Reason); }
GLOBAL void -Class_DeleteMask(const int Class, const char *Mask) +Class_DeleteMask(const int Class, const char *Pattern) { + char mask[MASK_LEN]; + assert(Class < CLASS_COUNT); assert(Mask != NULL);
- Lists_Del(&My_Classes[Class], Lists_MakeMask(Mask)); + Lists_MakeMask(Pattern, mask, sizeof(mask)); + Lists_Del(&My_Classes[Class], mask); }
GLOBAL struct list_head * diff --git a/src/ngircd/class.h b/src/ngircd/class.h index ba2e160..f118284 100644 --- a/src/ngircd/class.h +++ b/src/ngircd/class.h @@ -25,9 +25,9 @@ GLOBAL void Class_Init PARAMS((void)); GLOBAL void Class_Exit PARAMS((void));
-GLOBAL bool Class_AddMask PARAMS((const int Class, const char *Mask, +GLOBAL bool Class_AddMask PARAMS((const int Class, const char *Pattern, const time_t ValidUntil, const char *Reason)); -GLOBAL void Class_DeleteMask PARAMS((const int Class, const char *Mask)); +GLOBAL void Class_DeleteMask PARAMS((const int Class, const char *Pattern));
GLOBAL bool Class_GetMemberReason PARAMS((const int Class, CLIENT *Client, char *reason, size_t len)); diff --git a/src/ngircd/defines.h b/src/ngircd/defines.h index 6b92a69..cffbfad 100644 --- a/src/ngircd/defines.h +++ b/src/ngircd/defines.h @@ -50,7 +50,6 @@ /** Max. length of random salt */ #define RANDOM_SALT_LEN 32
- /* Size of structures */
/** Max. count of configurable servers. */ @@ -114,6 +113,9 @@ /** Max. host name length (including NULL). */ #define CLIENT_HOST_LEN 64
+/** Max. mask lenght (including NULL). */ +#define MASK_LEN (2 * CLIENT_HOST_LEN) + /** Max. length of all client modes (including NULL). */ #define CLIENT_MODE_LEN 21
diff --git a/src/ngircd/irc-mode.c b/src/ngircd/irc-mode.c index b5f28fa..765de39 100644 --- a/src/ngircd/irc-mode.c +++ b/src/ngircd/irc-mode.c @@ -980,7 +980,7 @@ static bool Add_To_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, const char *Pattern) { - const char *mask; + char mask[MASK_LEN]; struct list_head *list = NULL; long int current_count;
@@ -989,7 +989,7 @@ Add_To_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, assert(Pattern != NULL); assert(what == 'I' || what == 'b' || what == 'e');
- mask = Lists_MakeMask(Pattern); + Lists_MakeMask(Pattern, mask, sizeof(mask)); current_count = Lists_Count(Channel_GetListInvites(Channel)) + Lists_Count(Channel_GetListExcepts(Channel)) + Lists_Count(Channel_GetListBans(Channel)); @@ -1047,7 +1047,7 @@ static bool Del_From_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, const char *Pattern) { - const char *mask; + char mask[MASK_LEN]; struct list_head *list = NULL;
assert(Client != NULL); @@ -1055,7 +1055,7 @@ Del_From_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, assert(Pattern != NULL); assert(what == 'I' || what == 'b' || what == 'e');
- mask = Lists_MakeMask(Pattern); + Lists_MakeMask(Pattern, mask, sizeof(mask));
switch (what) { case 'I': diff --git a/src/ngircd/lists.c b/src/ngircd/lists.c index bab30f2..9ebd890 100644 --- a/src/ngircd/lists.c +++ b/src/ngircd/lists.c @@ -34,8 +34,6 @@ #include "exp.h" #include "lists.h"
-#define MASK_LEN (2*CLIENT_HOST_LEN) - struct list_elem { struct list_elem *next; /** pointer to next list element */ char mask[MASK_LEN]; /** IRC mask */ @@ -262,17 +260,13 @@ Lists_CheckDupeMask(const struct list_head *h, const char *Mask ) /** * Generate a valid IRC mask from "any" string given. * - * Attention: This mask is only valid until the next call to Lists_MakeMask(), - * because a single global buffer ist used! You have to copy the generated - * mask to some sane location yourself! - * * @param Pattern Source string to generate an IRC mask for. - * @return Pointer to global result buffer. + * @param mask Buffer to store the mask. + * @param len Size of the buffer. */ -GLOBAL const char * -Lists_MakeMask(const char *Pattern) +GLOBAL void +Lists_MakeMask(const char *Pattern, char *mask, size_t len) { - static char TheMask[MASK_LEN]; char *excl, *at;
assert(Pattern != NULL); @@ -285,30 +279,22 @@ Lists_MakeMask(const char *Pattern)
if (!at && !excl) { /* Neither "!" nor "@" found: use string as nickname */ - strlcpy(TheMask, Pattern, sizeof(TheMask) - 5); - strlcat(TheMask, "!*@*", sizeof(TheMask)); - return TheMask; - } - - if (!at && excl) { + strlcpy(mask, Pattern, len); + strlcat(mask, "!*@*", len); + } else if (!at && excl) { /* Domain part is missing */ - strlcpy(TheMask, Pattern, sizeof(TheMask) - 3); - strlcat(TheMask, "@*", sizeof(TheMask)); - return TheMask; - } - - if (at && !excl) { + strlcpy(mask, Pattern, len); + strlcat(mask, "@*", len); + } else if (at && !excl) { /* User name is missing */ *at = '\0'; at++; - strlcpy(TheMask, Pattern, sizeof(TheMask) - 5); - strlcat(TheMask, "!*@", sizeof(TheMask)); - strlcat(TheMask, at, sizeof(TheMask)); - return TheMask; + strlcpy(mask, Pattern, len); + strlcat(mask, "!*@", len); + strlcat(mask, at, len); + } else { + /* All parts (nick, user and domain name) are given */ + strlcpy(mask, Pattern, len); } - - /* All parts (nick, user and domain name) are given */ - strlcpy(TheMask, Pattern, sizeof(TheMask)); - return TheMask; } /* Lists_MakeMask */
/** diff --git a/src/ngircd/lists.h b/src/ngircd/lists.h index eb863db..db0f11a 100644 --- a/src/ngircd/lists.h +++ b/src/ngircd/lists.h @@ -42,7 +42,7 @@ GLOBAL unsigned long Lists_Count PARAMS((struct list_head *h));
GLOBAL void Lists_Free PARAMS((struct list_head *head));
-GLOBAL const char *Lists_MakeMask PARAMS((const char *Pattern)); +GLOBAL void Lists_MakeMask PARAMS((const char *Pattern, char *mask, size_t len)); GLOBAL const char *Lists_GetMask PARAMS((const struct list_elem *e)); GLOBAL const char *Lists_GetReason PARAMS((const struct list_elem *e)); GLOBAL time_t Lists_GetValidity PARAMS((const struct list_elem *e));