/**
* struct Hook - A list of user hooks
*/
+TAILQ_HEAD(HookHead, Hook);
struct Hook
{
int type; /**< hook type */
struct Regex rx; /**< regular expression */
char *command; /**< filename, command or pattern to execute */
struct Pattern *pattern; /**< used for fcc,save,send-hook */
- struct Hook *next;
+ TAILQ_ENTRY(Hook) entries;
};
-static struct Hook *Hooks = NULL;
+static struct HookHead Hooks = TAILQ_HEAD_INITIALIZER(Hooks);
static int current_hook_type = 0;
}
/* check to make sure that a matching hook doesn't already exist */
- for (ptr = Hooks; ptr; ptr = ptr->next)
+ TAILQ_FOREACH(ptr, &Hooks, entries)
{
if (data & MUTT_GLOBALHOOK)
{
return 0;
}
}
- if (!ptr->next)
- break;
}
if (data & (MUTT_SENDHOOK | MUTT_SEND2HOOK | MUTT_SAVEHOOK | MUTT_FCCHOOK |
}
}
- if (ptr)
- {
- ptr->next = safe_calloc(1, sizeof(struct Hook));
- ptr = ptr->next;
- }
- else
- Hooks = ptr = safe_calloc(1, sizeof(struct Hook));
+ ptr = safe_calloc(1, sizeof(struct Hook));
ptr->type = data;
ptr->command = command.data;
ptr->pattern = pat;
ptr->rx.pattern = pattern.data;
ptr->rx.rx = rx;
ptr->rx.not = not;
+ TAILQ_INSERT_TAIL(&Hooks, ptr, entries);
return 0;
error:
static void delete_hooks(int type)
{
struct Hook *h = NULL;
- struct Hook *prev = NULL;
+ struct Hook *tmp = NULL;
- while (h = Hooks, h && (type == 0 || type == h->type))
+ TAILQ_FOREACH_SAFE(h, &Hooks, entries, tmp)
{
- Hooks = h->next;
- delete_hook(h);
- }
-
- prev = h; /* Unused assignment to avoid compiler warnings */
-
- while (h)
- {
- if (type == h->type)
+ if (type == 0 || type == h->type)
{
- prev->next = h->next;
+ TAILQ_REMOVE(&Hooks, h, entries);
delete_hook(h);
}
- else
- prev = h;
- h = prev->next;
}
}
void mutt_folder_hook(char *path)
{
- struct Hook *tmp = Hooks;
+ struct Hook *tmp = NULL;
struct Buffer err, token;
current_hook_type = MUTT_FOLDERHOOK;
err.dsize = STRING;
err.data = safe_malloc(err.dsize);
mutt_buffer_init(&token);
- for (; tmp; tmp = tmp->next)
+ TAILQ_FOREACH(tmp, &Hooks, entries)
{
if (!tmp->command)
continue;
char *mutt_find_hook(int type, const char *pat)
{
- struct Hook *tmp = Hooks;
+ struct Hook *tmp = NULL;
- for (; tmp; tmp = tmp->next)
+ TAILQ_FOREACH(tmp, &Hooks, entries)
+ {
if (tmp->type & type)
{
if (regexec(tmp->rx.rx, pat, 0, NULL, 0) == 0)
return tmp->command;
}
+ }
return NULL;
}
err.data = safe_malloc(err.dsize);
mutt_buffer_init(&token);
memset(&cache, 0, sizeof(cache));
- for (hook = Hooks; hook; hook = hook->next)
+ TAILQ_FOREACH(hook, &Hooks, entries)
{
if (!hook->command)
continue;
memset(&cache, 0, sizeof(cache));
/* determine if a matching hook exists */
- for (hook = Hooks; hook; hook = hook->next)
+ TAILQ_FOREACH(hook, &Hooks, entries)
{
if (!hook->command)
continue;
static char *_mutt_string_hook(const char *match, int hook)
{
- struct Hook *tmp = Hooks;
+ struct Hook *tmp = NULL;
- for (; tmp; tmp = tmp->next)
+ TAILQ_FOREACH(tmp, &Hooks, entries)
{
if ((tmp->type & hook) &&
((match && regexec(tmp->rx.rx, match, 0, NULL, 0) == 0) ^ tmp->rx.not))
static void _mutt_list_hook(struct STailQHead *matches, const char *match, int hook)
{
- struct Hook *tmp = Hooks;
+ struct Hook *tmp = NULL;
- for (; tmp; tmp = tmp->next)
+ TAILQ_FOREACH(tmp, &Hooks, entries)
{
if ((tmp->type & hook) &&
((match && regexec(tmp->rx.rx, match, 0, NULL, 0) == 0) ^ tmp->rx.not))
err.data = safe_malloc(err.dsize);
mutt_buffer_init(&token);
- for (hook = Hooks; hook; hook = hook->next)
+ TAILQ_FOREACH(hook, &Hooks, entries)
{
if (!(hook->command && (hook->type & MUTT_ACCOUNTHOOK)))
continue;
err.dsize = sizeof(buf);
mutt_buffer_init(&token);
- for (hook = Hooks; hook; hook = hook->next)
+ TAILQ_FOREACH(hook, &Hooks, entries)
{
if (!(hook->command && (hook->type & MUTT_TIMEOUTHOOK)))
continue;
err.dsize = sizeof(buf);
mutt_buffer_init(&token);
- for (hook = Hooks; hook; hook = hook->next)
+ TAILQ_FOREACH(hook, &Hooks, entries)
{
if (!(hook->command && (hook->type & type)))
continue;