aboutsummaryrefslogtreecommitdiff
path: root/src/gnunet_chat_lib_intern.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnunet_chat_lib_intern.c')
-rw-r--r--src/gnunet_chat_lib_intern.c124
1 files changed, 124 insertions, 0 deletions
diff --git a/src/gnunet_chat_lib_intern.c b/src/gnunet_chat_lib_intern.c
new file mode 100644
index 0000000..8ccfce5
--- /dev/null
+++ b/src/gnunet_chat_lib_intern.c
@@ -0,0 +1,124 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2021 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet 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 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20/*
21 * @author Tobias Frisch
22 * @file gnunet_chat_lib_intern.c
23 */
24
25#define GNUNET_UNUSED __attribute__ ((unused))
26
27struct GNUNET_CHAT_HandleIterateContacts
28{
29 struct GNUNET_CHAT_Handle *handle;
30 GNUNET_CHAT_ContactCallback cb;
31 void *cls;
32};
33
34int
35it_handle_iterate_contacts (void *cls,
36 GNUNET_UNUSED const struct GNUNET_ShortHashCode *key,
37 void *value)
38{
39 struct GNUNET_CHAT_HandleIterateContacts *it = cls;
40
41 if (!(it->cb))
42 return GNUNET_YES;
43
44 struct GNUNET_CHAT_Contact *contact = value;
45
46 return it->cb(it->cls, it->handle, contact);
47}
48
49struct GNUNET_CHAT_HandleIterateGroups
50{
51 struct GNUNET_CHAT_Handle *handle;
52 GNUNET_CHAT_GroupCallback cb;
53 void *cls;
54};
55
56int
57it_handle_iterate_groups (void *cls,
58 GNUNET_UNUSED const struct GNUNET_HashCode *key,
59 void *value)
60{
61 struct GNUNET_CHAT_HandleIterateGroups *it = cls;
62
63 if (!(it->cb))
64 return GNUNET_YES;
65
66 struct GNUNET_CHAT_Group *group = value;
67
68 return it->cb(it->cls, it->handle, group);
69}
70
71struct GNUNET_CHAT_GroupIterateContacts
72{
73 struct GNUNET_CHAT_Group *group;
74 GNUNET_CHAT_GroupContactCallback cb;
75 void *cls;
76};
77
78int
79it_group_iterate_contacts (void* cls,
80 GNUNET_UNUSED struct GNUNET_MESSENGER_Room *room,
81 const struct GNUNET_MESSENGER_Contact *member)
82{
83 struct GNUNET_CHAT_GroupIterateContacts *it = cls;
84
85 if (!(it->cb))
86 return GNUNET_YES;
87
88 struct GNUNET_ShortHashCode shorthash;
89 util_shorthash_from_member(member, &shorthash);
90
91 struct GNUNET_CHAT_Contact *contact = GNUNET_CONTAINER_multishortmap_get(
92 it->group->handle->contacts, &shorthash
93 );
94
95 return it->cb(it->cls, it->group, contact);
96}
97
98struct GNUNET_CHAT_ContextIterateMessages
99{
100 struct GNUNET_CHAT_Context *context;
101 GNUNET_CHAT_ContextMessageCallback cb;
102 void *cls;
103};
104
105int
106it_context_iterate_messages (void *cls,
107 GNUNET_UNUSED const struct GNUNET_HashCode *key,
108 void *value)
109{
110 struct GNUNET_CHAT_ContextIterateMessages *it = cls;
111
112 if (!(it->cb))
113 return GNUNET_YES;
114
115 struct GNUNET_CHAT_Message *message = value;
116
117 return it->cb(it->cls, it->context, message);
118}
119
120
121
122
123
124