]>
Commit | Line | Data |
---|---|---|
a5b38c5b DL |
1 | /* |
2 | * Copyright (c) 2016 David Lamparter, for NetDEF, Inc. | |
3 | * | |
bbfeedb5 DL |
4 | * Permission to use, copy, modify, and distribute this software for any |
5 | * purpose with or without fee is hereby granted, provided that the above | |
6 | * copyright notice and this permission notice appear in all copies. | |
a5b38c5b | 7 | * |
bbfeedb5 DL |
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
a5b38c5b DL |
15 | */ |
16 | ||
b45ac5f5 DL |
17 | #ifdef HAVE_CONFIG_H |
18 | #include "config.h" | |
19 | #endif | |
20 | ||
a5b38c5b DL |
21 | #include "memory.h" |
22 | #include "hook.h" | |
23 | ||
24 | DEFINE_MTYPE_STATIC(LIB, HOOK_ENTRY, "Hook entry") | |
25 | ||
26 | void _hook_register(struct hook *hook, void *funcptr, void *arg, bool has_arg, | |
08c4c73b DL |
27 | struct frrmod_runtime *module, const char *funcname, |
28 | int priority) | |
a5b38c5b | 29 | { |
08c4c73b | 30 | struct hookent *he = XCALLOC(MTYPE_HOOK_ENTRY, sizeof(*he)), **pos; |
a5b38c5b DL |
31 | he->hookfn = funcptr; |
32 | he->hookarg = arg; | |
33 | he->has_arg = has_arg; | |
34 | he->module = module; | |
35 | he->fnname = funcname; | |
08c4c73b | 36 | he->priority = priority; |
a5b38c5b | 37 | |
08c4c73b | 38 | for (pos = &hook->entries; *pos; pos = &(*pos)->next) |
996c9314 LB |
39 | if (hook->reverse ? (*pos)->priority < priority |
40 | : (*pos)->priority >= priority) | |
08c4c73b DL |
41 | break; |
42 | ||
43 | he->next = *pos; | |
44 | *pos = he; | |
a5b38c5b DL |
45 | } |
46 | ||
d62a17ae | 47 | void _hook_unregister(struct hook *hook, void *funcptr, void *arg, bool has_arg) |
a5b38c5b DL |
48 | { |
49 | struct hookent *he, **prev; | |
50 | ||
51 | for (prev = &hook->entries; (he = *prev) != NULL; prev = &he->next) | |
52 | if (he->hookfn == funcptr && he->hookarg == arg | |
d62a17ae | 53 | && he->has_arg == has_arg) { |
a5b38c5b DL |
54 | *prev = he->next; |
55 | XFREE(MTYPE_HOOK_ENTRY, he); | |
56 | break; | |
57 | } | |
58 | } |