]> arthur.barton.de Git - ngircd-alex.git/commitdiff
Change Lists_MakeMask() to receive a buffer for the mask
authorFederico G. Schwindt <fgsch@lodoss.net>
Fri, 19 Apr 2013 23:19:03 +0000 (00:19 +0100)
committerFederico G. Schwindt <fgsch@lodoss.net>
Fri, 19 Apr 2013 23:43:47 +0000 (00:43 +0100)
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
src/ngircd/class.h
src/ngircd/defines.h
src/ngircd/irc-mode.c
src/ngircd/lists.c
src/ngircd/lists.h

index 800e99353647f8758488a30db2d8f41259dc1129..156f943ef9a318269edb487ccef5c6168af11487 100644 (file)
@@ -98,24 +98,30 @@ Class_HandleServerBans(CLIENT *Client)
 
 
 GLOBAL bool
 
 
 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)
 {
              const char *Reason)
 {
+       char mask[MASK_LEN];
+
        assert(Class < CLASS_COUNT);
        assert(Mask != NULL);
        assert(Reason != NULL);
 
        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
                         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);
 
        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 *
 }
 
 GLOBAL struct list_head *
index ba2e16069def9e0ad4abb365a97462cef3c46ec9..f118284b8a875cc343791a6672f32919be3a3203 100644 (file)
@@ -25,9 +25,9 @@
 GLOBAL void Class_Init PARAMS((void));
 GLOBAL void Class_Exit PARAMS((void));
 
 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));
                                  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));
 
 GLOBAL bool Class_GetMemberReason PARAMS((const int Class, CLIENT *Client,
                                          char *reason, size_t len));
index 6b92a699ffa9b0c7c8e57ca9fa05ca9427a5d499..cffbfadfa10cdb8ecca525c8d1c787bd650ee71c 100644 (file)
@@ -50,7 +50,6 @@
 /** Max. length of random salt */
 #define RANDOM_SALT_LEN 32
 
 /** Max. length of random salt */
 #define RANDOM_SALT_LEN 32
 
-
 /* Size of structures */
 
 /** Max. count of configurable servers. */
 /* Size of structures */
 
 /** Max. count of configurable servers. */
 /** Max. host name length (including NULL). */
 #define CLIENT_HOST_LEN 64
 
 /** 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
 
 /** Max. length of all client modes (including NULL). */
 #define CLIENT_MODE_LEN 21
 
index b5f28fa36d73cc0f3bac75d394d1504c667b79a7..765de394483b8880b0bdc149e6ef28e46d963991 100644 (file)
@@ -980,7 +980,7 @@ static bool
 Add_To_List(char what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel,
            const char *Pattern)
 {
 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;
 
        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');
 
        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));
        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)
 {
 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);
        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');
 
        assert(Pattern != NULL);
        assert(what == 'I' || what == 'b' || what == 'e');
 
-       mask = Lists_MakeMask(Pattern);
+       Lists_MakeMask(Pattern, mask, sizeof(mask));
 
        switch (what) {
                case 'I':
 
        switch (what) {
                case 'I':
index bab30f221be15766267347cf2a0f9f14ae5e92de..9ebd89067fb73f2dfa3a07d28924a65ca0f265e4 100644 (file)
@@ -34,8 +34,6 @@
 #include "exp.h"
 #include "lists.h"
 
 #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 */
 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.
  *
 /**
  * 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.
  * @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);
        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 */
 
        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 */
                /* 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++;
                /* 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 */
 
 /**
 } /* Lists_MakeMask */
 
 /**
index eb863db9f0a08c02aa6740a46f2547ae3761ea5e..db0f11a9603691f9eb64f5fcf90b638c007a0876 100644 (file)
@@ -42,7 +42,7 @@ GLOBAL unsigned long Lists_Count PARAMS((struct list_head *h));
 
 GLOBAL void Lists_Free PARAMS((struct list_head *head));
 
 
 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));
 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));