changelog: mention hippotat
[secnet] / comm-common.c
1 /*
2 * This file is part of secnet.
3 * See README for full list of copyright holders.
4 *
5 * secnet is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version d of the License, or
8 * (at your option) any later version.
9 *
10 * secnet is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * version 3 along with secnet; if not, see
17 * https://www.gnu.org/licenses/gpl.html.
18 */
19
20 #include "secnet.h"
21 #include "comm-common.h"
22
23 struct comm_clientinfo *comm_clientinfo_ignore(void *state, dict_t *dict,
24 struct cloc cloc)
25 {
26 return 0;
27 }
28
29 void comm_request_notify(void *commst, void *nst, comm_notify_fn *fn)
30 {
31 struct commcommon *st=commst;
32 struct comm_notify_entry *n;
33
34 NEW(n);
35 n->fn=fn;
36 n->state=nst;
37 LIST_INSERT_HEAD(&st->notify, n, entry);
38 }
39
40 void comm_release_notify(void *commst, void *nst, comm_notify_fn *fn)
41 {
42 struct commcommon *st=commst;
43 struct comm_notify_entry *n, *t;
44
45 /* XXX untested */
46 LIST_FOREACH_SAFE(n, &st->notify, entry, t) {
47 if (n->state==nst && n->fn==fn) {
48 LIST_REMOVE(n, entry);
49 free(n);
50 }
51 }
52 }
53
54 bool_t comm_notify(struct comm_notify_list *notify,
55 struct buffer_if *buf, const struct comm_addr *ca)
56 {
57 struct comm_notify_entry *n;
58
59 LIST_FOREACH(n, notify, entry) {
60 if (n->fn(n->state, buf, ca)) {
61 return True;
62 }
63 }
64 return False;
65 }
66
67 void comm_apply(struct commcommon *cc, void *st)
68 {
69 assert(cc==st);
70 cc->cl.type=CL_COMM;
71 cc->cl.apply=NULL;
72 cc->cl.interface=&cc->ops;
73 cc->ops.st=cc;
74 cc->ops.request_notify=comm_request_notify;
75 cc->ops.release_notify=comm_release_notify;
76 LIST_INIT(&cc->notify);
77 cc->rbuf=NULL;
78 }