diff options
Diffstat (limited to 'src/identity/identity_api_suffix_lookup.c')
-rw-r--r-- | src/identity/identity_api_suffix_lookup.c | 122 |
1 files changed, 60 insertions, 62 deletions
diff --git a/src/identity/identity_api_suffix_lookup.c b/src/identity/identity_api_suffix_lookup.c index 685030e40..51d8f39a6 100644 --- a/src/identity/identity_api_suffix_lookup.c +++ b/src/identity/identity_api_suffix_lookup.c | |||
@@ -16,7 +16,7 @@ | |||
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
18 | SPDX-License-Identifier: AGPL3.0-or-later | 18 | SPDX-License-Identifier: AGPL3.0-or-later |
19 | */ | 19 | */ |
20 | 20 | ||
21 | /** | 21 | /** |
22 | * @file identity/identity_api_suffix_lookup.c | 22 | * @file identity/identity_api_suffix_lookup.c |
@@ -28,15 +28,13 @@ | |||
28 | #include "gnunet_identity_service.h" | 28 | #include "gnunet_identity_service.h" |
29 | #include "identity.h" | 29 | #include "identity.h" |
30 | 30 | ||
31 | #define LOG(kind, ...) GNUNET_log_from (kind, "identity-api", __VA_ARGS__) | 31 | #define LOG(kind, ...) GNUNET_log_from(kind, "identity-api", __VA_ARGS__) |
32 | 32 | ||
33 | 33 | ||
34 | /** | 34 | /** |
35 | * Handle for ego lookup. | 35 | * Handle for ego lookup. |
36 | */ | 36 | */ |
37 | struct GNUNET_IDENTITY_EgoSuffixLookup | 37 | struct GNUNET_IDENTITY_EgoSuffixLookup { |
38 | { | ||
39 | |||
40 | /** | 38 | /** |
41 | * Connection to service. | 39 | * Connection to service. |
42 | */ | 40 | */ |
@@ -68,11 +66,11 @@ struct GNUNET_IDENTITY_EgoSuffixLookup | |||
68 | * @return #GNUNET_OK if the message is well-formed | 66 | * @return #GNUNET_OK if the message is well-formed |
69 | */ | 67 | */ |
70 | static int | 68 | static int |
71 | check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) | 69 | check_identity_result_code(void *cls, const struct ResultCodeMessage *rcm) |
72 | { | 70 | { |
73 | (void) cls; | 71 | (void)cls; |
74 | if (sizeof (*rcm) != htons (rcm->header.size)) | 72 | if (sizeof(*rcm) != htons(rcm->header.size)) |
75 | GNUNET_MQ_check_zero_termination (rcm); | 73 | GNUNET_MQ_check_zero_termination(rcm); |
76 | return GNUNET_OK; | 74 | return GNUNET_OK; |
77 | } | 75 | } |
78 | 76 | ||
@@ -84,13 +82,13 @@ check_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) | |||
84 | * @param rcm result message received | 82 | * @param rcm result message received |
85 | */ | 83 | */ |
86 | static void | 84 | static void |
87 | handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) | 85 | handle_identity_result_code(void *cls, const struct ResultCodeMessage *rcm) |
88 | { | 86 | { |
89 | struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls; | 87 | struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls; |
90 | 88 | ||
91 | (void) rcm; | 89 | (void)rcm; |
92 | el->cb (el->cb_cls, NULL, NULL); | 90 | el->cb(el->cb_cls, NULL, NULL); |
93 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (el); | 91 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel(el); |
94 | } | 92 | } |
95 | 93 | ||
96 | 94 | ||
@@ -102,19 +100,19 @@ handle_identity_result_code (void *cls, const struct ResultCodeMessage *rcm) | |||
102 | * @return #GNUNET_OK if the message is well-formed | 100 | * @return #GNUNET_OK if the message is well-formed |
103 | */ | 101 | */ |
104 | static int | 102 | static int |
105 | check_identity_update (void *cls, const struct UpdateMessage *um) | 103 | check_identity_update(void *cls, const struct UpdateMessage *um) |
106 | { | 104 | { |
107 | uint16_t size = ntohs (um->header.size); | 105 | uint16_t size = ntohs(um->header.size); |
108 | uint16_t name_len = ntohs (um->name_len); | 106 | uint16_t name_len = ntohs(um->name_len); |
109 | const char *str = (const char *) &um[1]; | 107 | const char *str = (const char *)&um[1]; |
110 | 108 | ||
111 | (void) cls; | 109 | (void)cls; |
112 | if ((size != name_len + sizeof (struct UpdateMessage)) || | 110 | if ((size != name_len + sizeof(struct UpdateMessage)) || |
113 | ((0 != name_len) && ('\0' != str[name_len - 1]))) | 111 | ((0 != name_len) && ('\0' != str[name_len - 1]))) |
114 | { | 112 | { |
115 | GNUNET_break (0); | 113 | GNUNET_break(0); |
116 | return GNUNET_SYSERR; | 114 | return GNUNET_SYSERR; |
117 | } | 115 | } |
118 | return GNUNET_OK; | 116 | return GNUNET_OK; |
119 | } | 117 | } |
120 | 118 | ||
@@ -126,14 +124,14 @@ check_identity_update (void *cls, const struct UpdateMessage *um) | |||
126 | * @param um message received | 124 | * @param um message received |
127 | */ | 125 | */ |
128 | static void | 126 | static void |
129 | handle_identity_update (void *cls, const struct UpdateMessage *um) | 127 | handle_identity_update(void *cls, const struct UpdateMessage *um) |
130 | { | 128 | { |
131 | struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls; | 129 | struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls; |
132 | uint16_t name_len = ntohs (um->name_len); | 130 | uint16_t name_len = ntohs(um->name_len); |
133 | const char *str = (0 == name_len) ? NULL : (const char *) &um[1]; | 131 | const char *str = (0 == name_len) ? NULL : (const char *)&um[1]; |
134 | 132 | ||
135 | el->cb (el->cb_cls, &um->private_key, str); | 133 | el->cb(el->cb_cls, &um->private_key, str); |
136 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (el); | 134 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel(el); |
137 | } | 135 | } |
138 | 136 | ||
139 | 137 | ||
@@ -146,13 +144,13 @@ handle_identity_update (void *cls, const struct UpdateMessage *um) | |||
146 | * @param error error code | 144 | * @param error error code |
147 | */ | 145 | */ |
148 | static void | 146 | static void |
149 | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | 147 | mq_error_handler(void *cls, enum GNUNET_MQ_Error error) |
150 | { | 148 | { |
151 | struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls; | 149 | struct GNUNET_IDENTITY_EgoSuffixLookup *el = cls; |
152 | 150 | ||
153 | (void) error; | 151 | (void)error; |
154 | el->cb (el->cb_cls, NULL, NULL); | 152 | el->cb(el->cb_cls, NULL, NULL); |
155 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (el); | 153 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel(el); |
156 | } | 154 | } |
157 | 155 | ||
158 | 156 | ||
@@ -166,46 +164,46 @@ mq_error_handler (void *cls, enum GNUNET_MQ_Error error) | |||
166 | * @return NULL on error | 164 | * @return NULL on error |
167 | */ | 165 | */ |
168 | struct GNUNET_IDENTITY_EgoSuffixLookup * | 166 | struct GNUNET_IDENTITY_EgoSuffixLookup * |
169 | GNUNET_IDENTITY_ego_lookup_by_suffix (const struct GNUNET_CONFIGURATION_Handle *cfg, | 167 | GNUNET_IDENTITY_ego_lookup_by_suffix(const struct GNUNET_CONFIGURATION_Handle *cfg, |
170 | const char *suffix, | 168 | const char *suffix, |
171 | GNUNET_IDENTITY_EgoSuffixCallback cb, | 169 | GNUNET_IDENTITY_EgoSuffixCallback cb, |
172 | void *cb_cls) | 170 | void *cb_cls) |
173 | { | 171 | { |
174 | struct GNUNET_IDENTITY_EgoSuffixLookup *el; | 172 | struct GNUNET_IDENTITY_EgoSuffixLookup *el; |
175 | struct GNUNET_MQ_Envelope *env; | 173 | struct GNUNET_MQ_Envelope *env; |
176 | struct GNUNET_MessageHeader *req; | 174 | struct GNUNET_MessageHeader *req; |
177 | size_t nlen; | 175 | size_t nlen; |
178 | 176 | ||
179 | GNUNET_assert (NULL != cb); | 177 | GNUNET_assert(NULL != cb); |
180 | el = GNUNET_new (struct GNUNET_IDENTITY_EgoSuffixLookup); | 178 | el = GNUNET_new(struct GNUNET_IDENTITY_EgoSuffixLookup); |
181 | el->cb = cb; | 179 | el->cb = cb; |
182 | el->cb_cls = cb_cls; | 180 | el->cb_cls = cb_cls; |
183 | { | 181 | { |
184 | struct GNUNET_MQ_MessageHandler handlers[] = | 182 | struct GNUNET_MQ_MessageHandler handlers[] = |
185 | {GNUNET_MQ_hd_var_size (identity_result_code, | 183 | { GNUNET_MQ_hd_var_size(identity_result_code, |
186 | GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, | 184 | GNUNET_MESSAGE_TYPE_IDENTITY_RESULT_CODE, |
187 | struct ResultCodeMessage, | 185 | struct ResultCodeMessage, |
188 | el), | 186 | el), |
189 | GNUNET_MQ_hd_var_size (identity_update, | 187 | GNUNET_MQ_hd_var_size(identity_update, |
190 | GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, | 188 | GNUNET_MESSAGE_TYPE_IDENTITY_UPDATE, |
191 | struct UpdateMessage, | 189 | struct UpdateMessage, |
192 | el), | 190 | el), |
193 | GNUNET_MQ_handler_end ()}; | 191 | GNUNET_MQ_handler_end() }; |
194 | 192 | ||
195 | el->mq = | 193 | el->mq = |
196 | GNUNET_CLIENT_connect (cfg, "identity", handlers, &mq_error_handler, el); | 194 | GNUNET_CLIENT_connect(cfg, "identity", handlers, &mq_error_handler, el); |
197 | } | 195 | } |
198 | if (NULL == el->mq) | 196 | if (NULL == el->mq) |
199 | { | 197 | { |
200 | GNUNET_break (0); | 198 | GNUNET_break(0); |
201 | GNUNET_free (el); | 199 | GNUNET_free(el); |
202 | return NULL; | 200 | return NULL; |
203 | } | 201 | } |
204 | el->suffix = GNUNET_strdup (suffix); | 202 | el->suffix = GNUNET_strdup(suffix); |
205 | nlen = strlen (suffix) + 1; | 203 | nlen = strlen(suffix) + 1; |
206 | env = GNUNET_MQ_msg_extra (req, nlen, GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX); | 204 | env = GNUNET_MQ_msg_extra(req, nlen, GNUNET_MESSAGE_TYPE_IDENTITY_LOOKUP_BY_SUFFIX); |
207 | memcpy (&req[1], suffix, nlen); | 205 | memcpy(&req[1], suffix, nlen); |
208 | GNUNET_MQ_send (el->mq, env); | 206 | GNUNET_MQ_send(el->mq, env); |
209 | return el; | 207 | return el; |
210 | } | 208 | } |
211 | 209 | ||
@@ -216,11 +214,11 @@ GNUNET_IDENTITY_ego_lookup_by_suffix (const struct GNUNET_CONFIGURATION_Handle * | |||
216 | * @param el handle for lookup to abort | 214 | * @param el handle for lookup to abort |
217 | */ | 215 | */ |
218 | void | 216 | void |
219 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel (struct GNUNET_IDENTITY_EgoSuffixLookup *el) | 217 | GNUNET_IDENTITY_ego_lookup_by_suffix_cancel(struct GNUNET_IDENTITY_EgoSuffixLookup *el) |
220 | { | 218 | { |
221 | GNUNET_MQ_destroy (el->mq); | 219 | GNUNET_MQ_destroy(el->mq); |
222 | GNUNET_free (el->suffix); | 220 | GNUNET_free(el->suffix); |
223 | GNUNET_free (el); | 221 | GNUNET_free(el); |
224 | } | 222 | } |
225 | 223 | ||
226 | 224 | ||