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 *
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));
/** Max. length of random salt */
#define RANDOM_SALT_LEN 32
-
/* Size of structures */
/** Max. count of configurable servers. */
/** 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
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;
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));
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);
assert(Pattern != NULL);
assert(what == 'I' || what == 'b' || what == 'e');
- mask = Lists_MakeMask(Pattern);
+ Lists_MakeMask(Pattern, mask, sizeof(mask));
switch (what) {
case 'I':
#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 */
/**
* 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);
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 */
/**
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));