diff options
Diffstat (limited to 'src/messenger/messenger_api_message_kind.c')
-rw-r--r-- | src/messenger/messenger_api_message_kind.c | 190 |
1 files changed, 0 insertions, 190 deletions
diff --git a/src/messenger/messenger_api_message_kind.c b/src/messenger/messenger_api_message_kind.c deleted file mode 100644 index 5a13620cc..000000000 --- a/src/messenger/messenger_api_message_kind.c +++ /dev/null | |||
@@ -1,190 +0,0 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2020--2023 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 src/messenger/gnunet-service-messenger_message_kind.c | ||
23 | * @brief GNUnet MESSENGER service | ||
24 | */ | ||
25 | |||
26 | #include "messenger_api_message_kind.h" | ||
27 | |||
28 | #include "platform.h" | ||
29 | #include "messenger_api_util.h" | ||
30 | |||
31 | struct GNUNET_MESSENGER_Message* | ||
32 | create_message_join (const struct GNUNET_IDENTITY_PrivateKey *key) | ||
33 | { | ||
34 | if (! key) | ||
35 | return NULL; | ||
36 | |||
37 | struct GNUNET_MESSENGER_Message *message = create_message ( | ||
38 | GNUNET_MESSENGER_KIND_JOIN); | ||
39 | |||
40 | if (! message) | ||
41 | return NULL; | ||
42 | |||
43 | GNUNET_IDENTITY_key_get_public (key, &(message->body.join.key)); | ||
44 | return message; | ||
45 | } | ||
46 | |||
47 | |||
48 | struct GNUNET_MESSENGER_Message* | ||
49 | create_message_leave () | ||
50 | { | ||
51 | return create_message (GNUNET_MESSENGER_KIND_LEAVE); | ||
52 | } | ||
53 | |||
54 | |||
55 | struct GNUNET_MESSENGER_Message* | ||
56 | create_message_name (const char *name) | ||
57 | { | ||
58 | if (! name) | ||
59 | return NULL; | ||
60 | |||
61 | struct GNUNET_MESSENGER_Message *message = create_message ( | ||
62 | GNUNET_MESSENGER_KIND_NAME); | ||
63 | |||
64 | if (! message) | ||
65 | return NULL; | ||
66 | |||
67 | message->body.name.name = GNUNET_strdup (name); | ||
68 | return message; | ||
69 | } | ||
70 | |||
71 | |||
72 | struct GNUNET_MESSENGER_Message* | ||
73 | create_message_key (const struct GNUNET_IDENTITY_PrivateKey *key) | ||
74 | { | ||
75 | if (! key) | ||
76 | return NULL; | ||
77 | |||
78 | struct GNUNET_MESSENGER_Message *message = create_message ( | ||
79 | GNUNET_MESSENGER_KIND_KEY); | ||
80 | |||
81 | if (! message) | ||
82 | return NULL; | ||
83 | |||
84 | GNUNET_IDENTITY_key_get_public (key, &(message->body.key.key)); | ||
85 | return message; | ||
86 | } | ||
87 | |||
88 | |||
89 | struct GNUNET_MESSENGER_Message* | ||
90 | create_message_id (const struct GNUNET_ShortHashCode *unique_id) | ||
91 | { | ||
92 | if (! unique_id) | ||
93 | return NULL; | ||
94 | |||
95 | struct GNUNET_MESSENGER_Message *message = create_message ( | ||
96 | GNUNET_MESSENGER_KIND_ID); | ||
97 | |||
98 | if (! message) | ||
99 | return NULL; | ||
100 | |||
101 | GNUNET_memcpy (&(message->body.id.id), unique_id, sizeof(struct | ||
102 | GNUNET_ShortHashCode)); | ||
103 | |||
104 | return message; | ||
105 | } | ||
106 | |||
107 | |||
108 | struct GNUNET_MESSENGER_Message* | ||
109 | create_message_request (const struct GNUNET_HashCode *hash) | ||
110 | { | ||
111 | if (! hash) | ||
112 | return NULL; | ||
113 | |||
114 | struct GNUNET_HashCode zero; | ||
115 | memset (&zero, 0, sizeof(zero)); | ||
116 | |||
117 | if (0 == GNUNET_CRYPTO_hash_cmp (hash, &zero)) | ||
118 | return NULL; | ||
119 | |||
120 | struct GNUNET_MESSENGER_Message *message = create_message ( | ||
121 | GNUNET_MESSENGER_KIND_REQUEST); | ||
122 | |||
123 | if (! message) | ||
124 | return NULL; | ||
125 | |||
126 | GNUNET_memcpy (&(message->body.request.hash), hash, sizeof(struct | ||
127 | GNUNET_HashCode)); | ||
128 | |||
129 | return message; | ||
130 | } | ||
131 | |||
132 | |||
133 | struct GNUNET_MESSENGER_Message* | ||
134 | create_message_invite (const struct GNUNET_PeerIdentity *door, | ||
135 | const struct GNUNET_HashCode *key) | ||
136 | { | ||
137 | if ((! door) || (! key)) | ||
138 | return NULL; | ||
139 | |||
140 | struct GNUNET_MESSENGER_Message *message = create_message ( | ||
141 | GNUNET_MESSENGER_KIND_INVITE); | ||
142 | |||
143 | if (! message) | ||
144 | return NULL; | ||
145 | |||
146 | GNUNET_memcpy (&(message->body.invite.door), door, sizeof(struct | ||
147 | GNUNET_PeerIdentity)); | ||
148 | GNUNET_memcpy (&(message->body.invite.key), key, sizeof(struct | ||
149 | GNUNET_HashCode)); | ||
150 | |||
151 | return message; | ||
152 | } | ||
153 | |||
154 | |||
155 | struct GNUNET_MESSENGER_Message* | ||
156 | create_message_text (const char *text) | ||
157 | { | ||
158 | if (! text) | ||
159 | return NULL; | ||
160 | |||
161 | struct GNUNET_MESSENGER_Message *message = create_message ( | ||
162 | GNUNET_MESSENGER_KIND_TEXT); | ||
163 | |||
164 | if (! message) | ||
165 | return NULL; | ||
166 | |||
167 | message->body.text.text = GNUNET_strdup (text); | ||
168 | return message; | ||
169 | } | ||
170 | |||
171 | |||
172 | struct GNUNET_MESSENGER_Message* | ||
173 | create_message_delete (const struct GNUNET_HashCode *hash, | ||
174 | const struct GNUNET_TIME_Relative delay) | ||
175 | { | ||
176 | if (! hash) | ||
177 | return NULL; | ||
178 | |||
179 | struct GNUNET_MESSENGER_Message *message = create_message ( | ||
180 | GNUNET_MESSENGER_KIND_DELETE); | ||
181 | |||
182 | if (! message) | ||
183 | return NULL; | ||
184 | |||
185 | GNUNET_memcpy (&(message->body.deletion.hash), hash, sizeof(struct | ||
186 | GNUNET_HashCode)); | ||
187 | message->body.deletion.delay = GNUNET_TIME_relative_hton (delay); | ||
188 | |||
189 | return message; | ||
190 | } | ||