1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-06 04:13:13 +02:00

New function AddListItemPrio, since we now use priorities in two places already (swhois, hooks).

This commit is contained in:
Bram Matthys
2015-07-10 11:10:10 +02:00
parent 9ca6d10785
commit 71d3e8dbfa
4 changed files with 58 additions and 39 deletions
+1
View File
@@ -129,6 +129,7 @@ extern int match_ipv6(struct IN_ADDR *addr, struct IN_ADDR *mask, int bits);
#endif
extern ConfigItem_ban *Find_ban_ip(aClient *sptr);
extern void add_ListItem(ListStruct *, ListStruct **);
extern void add_ListItemPrio(ListStructPrio *, ListStructPrio **, int);
extern ListStruct *del_ListItem(ListStruct *, ListStruct **);
extern aClient *find_match_server(char *mask);
extern MODVAR LoopStruct loop;
+9 -3
View File
@@ -118,6 +118,7 @@ typedef struct _configitem_include ConfigItem_include;
typedef struct _configitem_help ConfigItem_help;
typedef struct _configitem_offchans ConfigItem_offchans;
typedef struct liststruct ListStruct;
typedef struct liststructprio ListStructPrio;
#define CFG_TIME 0x0001
#define CFG_SIZE 0x0002
@@ -1509,14 +1510,19 @@ struct DSlink {
};
#define AddListItem(item,list) add_ListItem((ListStruct *)item, (ListStruct **)&list)
#define DelListItem(item,list) del_ListItem((ListStruct *)item, (ListStruct **)&list)
/* Backwards compatibility */
#define add_ConfigItem(item,list) add_ListItem((ListStruct *)item, (ListStruct **)&list)
#define del_ConfigItem(item,list) del_ListItem((ListStruct *)item, (ListStruct **)&list)
#define AddListItemPrio(item,list,prio) add_ListItemPrio((ListStructPrio *)item, (ListStructPrio **)&list, prio)
#define DelListItemPrio(item,list,prio) del_ListItem((ListStruct *)item, (ListStruct **)&list)
struct liststruct {
ListStruct *prev, *next;
};
struct liststructprio {
ListStructPrio *prev, *next;
int priority;
};
/* channel structure */
+46
View File
@@ -574,3 +574,49 @@ ListStruct *del_ListItem(ListStruct *item, ListStruct **list) {
}
return NULL;
}
/** Add item to list with a 'priority'.
* If there are multiple items with the same priority then it will be
* added as the last item within.
*/
void add_ListItemPrio(ListStructPrio *new, ListStructPrio **list, int priority)
{
ListStructPrio *x, *last = NULL;
if (!*list)
{
/* We are the only item. Easy. */
*list = new;
return;
}
for (x = *list; x; x = x->next)
{
last = x;
if (x->priority >= priority)
break;
}
if (x)
{
if (x->prev)
{
/* We will insert ourselves just before this item */
new->prev = x->prev;
new->next = x;
x->prev->next = new;
x->prev = new;
} else {
/* We are the new head */
*list = new;
new->next = x;
x->prev = new;
}
} else
{
/* We are the last item */
last->next = new;
new->prev = last;
}
}
+2 -36
View File
@@ -1244,42 +1244,8 @@ Hook *HookAddMain(Module *module, int hooktype, int priority, int (*func)(), voi
AddListItem(hookobj, module->objects);
module->errorcode = MODERR_NOERROR;
}
if (!Hooks[hooktype])
{
/* Nobody else using this hook. Easy. */
Hooks[hooktype] = p;
} else {
/* There are existing entries. Put our entry in the list, taking into account 'priority'. */
Hook *h, *last = NULL;
for (h = Hooks[hooktype]; h; h = h->next)
{
last = h;
if (h->priority >= priority)
break;
}
if (h)
{
if (h->prev)
{
/* We will insert ourselves just before this item */
p->prev = h->prev;
p->next = h;
h->prev->next = p;
h->prev = p;
} else {
/* We are the new head */
Hooks[hooktype] = p;
p->next = h;
h->prev = p;
}
} else
{
/* We are the last item */
last->next = p;
p->prev = last;
}
}
AddListItemPrio(p, Hooks[hooktype], p->priority);
return p;
}