Debian Codegraph @

modules/chanserv/chanserv.h

raw
1 #ifndef INLINE_CHANSERV_H
2 #define INLINE_CHANSERV_H
3
4 typedef void (*cs_cmd_proto)(sourceinfo_t*, int, char**);
5
6 static inline unsigned int custom_founder_check(void)
7 {
8 char *p;
9
10 if (chansvs.founder_flags != NULL && (p = strchr(chansvs.founder_flags, 'F')) != NULL)
11 return flags_to_bitmask(chansvs.founder_flags, 0);
12 else
13 return CA_INITIAL & ca_all;
14 }
15
16 struct prefix_action
17 {
18 bool en; /* en for "enable" */
19 char nick[]; /* CAREFUL! */
20 };
21
22 static inline void prefix_action_set(mowgli_list_t *actions, char *nick, bool en)
23 {
24 struct prefix_action *act;
25 mowgli_node_t *n;
26
27 MOWGLI_LIST_FOREACH(n, actions->head)
28 {
29 act = n->data;
30 if (!strcmp(act->nick, nick))
31 {
32 act->en = en;
33 return;
34 }
35 }
36
37 act = smalloc(sizeof(*act) + strlen(nick) + 1);
38 act->en = en;
39 strcpy(act->nick, nick);
40 mowgli_node_add(act, mowgli_node_create(), actions);
41 }
42
43 static inline void prefix_action_set_all(mowgli_list_t *actions, bool dfl, char *nicks)
44 {
45 char *nick, *strtokctx = NULL;
46 bool en;
47
48 nick = strtok_r(nicks, " ", &strtokctx);
49 do
50 {
51 switch (*nick)
52 {
53 case '-':
54 en = false;
55 nick++;
56 break;
57 case '+':
58 en = true;
59 nick++;
60 break;
61 default:
62 en = dfl;
63 }
64
65 if (!strcmp(nick, ""))
66 continue;
67
68 prefix_action_set(actions, nick, en);
69 } while ((nick = strtok_r(NULL, " ", &strtokctx)) != NULL);
70 }
71
72 static inline void prefix_action_clear(mowgli_list_t *actions)
73 {
74 mowgli_node_t *n, *tn;
75
76 MOWGLI_LIST_FOREACH_SAFE(n, tn, actions->head)
77 {
78 free(n->data);
79 mowgli_node_delete(n, actions);
80 mowgli_node_free(n);
81 }
82 }
83
84 #endif