mirror of
https://github.com/osmarks/ngircd.git
synced 2024-12-13 02:10:27 +00:00
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.
This commit is contained in:
parent
cde2e8a277
commit
3ab00e3a11
@ -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 *
|
||||
|
@ -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));
|
||||
|
@ -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
|
||||
|
||||
|
@ -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':
|
||||
|
@ -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 */
|
||||
|
||||
/**
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user