mirror of
https://github.com/osmarks/ngircd.git
synced 2024-12-12 18:00:28 +00:00
List and class handling: add optional "reason" text
Adjust Lists_Add() and Class_AddMask() accordingly, implement Lists_GetReason() and Lists_GetValidity().
This commit is contained in:
parent
1e054e0b82
commit
af70c3dbc9
@ -1003,7 +1003,7 @@ Channel_AddBan(CHANNEL *c, const char *mask )
|
||||
{
|
||||
struct list_head *h = Channel_GetListBans(c);
|
||||
LogDebug("Adding \"%s\" to \"%s\" %s list", mask, Channel_Name(c), "ban");
|
||||
return Lists_Add(h, mask, false);
|
||||
return Lists_Add(h, mask, false, NULL);
|
||||
}
|
||||
|
||||
|
||||
@ -1012,7 +1012,7 @@ Channel_AddInvite(CHANNEL *c, const char *mask, bool onlyonce)
|
||||
{
|
||||
struct list_head *h = Channel_GetListInvites(c);
|
||||
LogDebug("Adding \"%s\" to \"%s\" %s list", mask, Channel_Name(c), "invite");
|
||||
return Lists_Add(h, mask, onlyonce);
|
||||
return Lists_Add(h, mask, onlyonce, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
@ -56,12 +56,14 @@ Class_IsMember(const int Class, CLIENT *Client)
|
||||
}
|
||||
|
||||
GLOBAL bool
|
||||
Class_AddMask(const int Class, const char *Mask, time_t ValidUntil)
|
||||
Class_AddMask(const int Class, const char *Mask, time_t ValidUntil,
|
||||
const char *Reason)
|
||||
{
|
||||
assert(Class < CLASS_COUNT);
|
||||
assert(Mask != NULL);
|
||||
assert(Reason != NULL);
|
||||
|
||||
return Lists_Add(&My_Classes[Class], Mask, ValidUntil);
|
||||
return Lists_Add(&My_Classes[Class], Mask, ValidUntil, Reason);
|
||||
}
|
||||
|
||||
GLOBAL void
|
||||
|
@ -26,7 +26,7 @@ GLOBAL void Class_Init PARAMS((void));
|
||||
GLOBAL void Class_Exit PARAMS((void));
|
||||
|
||||
GLOBAL bool Class_AddMask PARAMS((const int Class, const char *Mask,
|
||||
const time_t ValidUntil));
|
||||
const time_t ValidUntil, const char *Reason));
|
||||
GLOBAL void Class_DeleteMask PARAMS((const int Class, const char *Mask));
|
||||
|
||||
GLOBAL bool Class_IsMember PARAMS((const int Class, CLIENT *Client));
|
||||
|
@ -39,6 +39,7 @@
|
||||
struct list_elem {
|
||||
struct list_elem *next;
|
||||
char mask[MASK_LEN];
|
||||
char *reason;
|
||||
time_t valid_until; /** 0: unlimited; 1: once; t(>1): until t */
|
||||
};
|
||||
|
||||
@ -49,6 +50,19 @@ Lists_GetMask(const struct list_elem *e)
|
||||
return e->mask;
|
||||
}
|
||||
|
||||
GLOBAL const char *
|
||||
Lists_GetReason(const struct list_elem *e)
|
||||
{
|
||||
assert(e != NULL);
|
||||
return e->reason;
|
||||
}
|
||||
|
||||
GLOBAL time_t
|
||||
Lists_GetValidity(const struct list_elem *e)
|
||||
{
|
||||
assert(e != NULL);
|
||||
return e->valid_until;
|
||||
}
|
||||
|
||||
GLOBAL struct list_elem*
|
||||
Lists_GetFirst(const struct list_head *h)
|
||||
@ -63,9 +77,18 @@ Lists_GetNext(const struct list_elem *e)
|
||||
return e->next;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Add a new mask to a list.
|
||||
*
|
||||
* @param header List head.
|
||||
* @param Mask The IRC mask to add to the list.
|
||||
* @param ValidUntil 0: unlimited, 1: only once, t>1: until given time_t.
|
||||
* @param Reason Reason string or NULL, if no reason should be saved.
|
||||
* @return true on success, false otherwise.
|
||||
*/
|
||||
bool
|
||||
Lists_Add(struct list_head *header, const char *Mask, time_t ValidUntil )
|
||||
Lists_Add(struct list_head *header, const char *Mask, time_t ValidUntil,
|
||||
const char *Reason)
|
||||
{
|
||||
struct list_elem *e, *newelem;
|
||||
|
||||
@ -82,7 +105,17 @@ Lists_Add(struct list_head *header, const char *Mask, time_t ValidUntil )
|
||||
return false;
|
||||
}
|
||||
|
||||
strlcpy( newelem->mask, Mask, sizeof( newelem->mask ));
|
||||
strlcpy(newelem->mask, Mask, sizeof(newelem->mask));
|
||||
if (Reason) {
|
||||
newelem->reason = malloc(strlen(Reason) + 1);
|
||||
if (newelem->reason)
|
||||
strlcpy(newelem->reason, Reason, strlen(Reason) + 1);
|
||||
else
|
||||
Log(LOG_EMERG,
|
||||
"Can't allocate memory for new list reason text!");
|
||||
}
|
||||
else
|
||||
newelem->reason = NULL;
|
||||
newelem->valid_until = ValidUntil;
|
||||
newelem->next = e;
|
||||
header->first = newelem;
|
||||
@ -100,6 +133,8 @@ Lists_Unlink(struct list_head *header, struct list_elem *p, struct list_elem *vi
|
||||
if (p) p->next = victim->next;
|
||||
else header->first = victim->next;
|
||||
|
||||
if (victim->reason)
|
||||
free(victim->reason);
|
||||
free(victim);
|
||||
}
|
||||
|
||||
@ -141,7 +176,9 @@ Lists_Free(struct list_head *head)
|
||||
LogDebug("Deleted \"%s\" from invite list" , e->mask);
|
||||
victim = e;
|
||||
e = e->next;
|
||||
free( victim );
|
||||
if (victim->reason)
|
||||
free(victim->reason);
|
||||
free(victim);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,8 @@ GLOBAL struct list_elem *Lists_GetNext PARAMS((const struct list_elem *));
|
||||
GLOBAL bool Lists_Check PARAMS((struct list_head *head, CLIENT *client ));
|
||||
GLOBAL bool Lists_CheckDupeMask PARAMS((const struct list_head *head, const char *mask ));
|
||||
|
||||
GLOBAL bool Lists_Add PARAMS((struct list_head *header, const char *Mask, time_t ValidUntil ));
|
||||
GLOBAL bool Lists_Add PARAMS((struct list_head *header, const char *Mask,
|
||||
time_t ValidUntil, const char *Reason));
|
||||
GLOBAL void Lists_Del PARAMS((struct list_head *head, const char *Mask ));
|
||||
|
||||
GLOBAL bool Lists_AlreadyRegistered PARAMS(( const struct list_head *head, const char *Mask));
|
||||
@ -40,7 +41,9 @@ GLOBAL bool Lists_AlreadyRegistered PARAMS(( const struct list_head *head, const
|
||||
GLOBAL void Lists_Free PARAMS(( struct list_head *head ));
|
||||
|
||||
GLOBAL const char *Lists_MakeMask PARAMS((const char *Pattern));
|
||||
GLOBAL const char *Lists_GetMask 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));
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user